package com.huangpuweb.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huangpuweb.api.Constants;
import com.huangpuweb.api.model.*;
import com.huangpuweb.api.model.dto.CrowdFlowDto;
import com.huangpuweb.api.service.*;
import com.huangpuweb.api.util.DateUtil;
import com.huangpuweb.api.util.MapUtil;
import com.huangpuweb.api.util.StringUtil;
import com.huangpuweb.api.util.ValidatorUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.*;

@Controller
@RequestMapping(value = "/crowd")
public class CrowdSituationController {

    private static Logger logger = Logger.getLogger(CrowdSituationController.class);

    private CrowdSituationApiService crowdSituationApiService;

    private String[] spotCodes = {"SHHPQ_YUYUAN_NEIQUAN","SHHPQ_NANJINGLU","SHHPQ_NANJINGLUDONGTUO","SHHPQ_WAITAN_Ali"};

    private String[] spotIds = {"YUYUAN","XINTIANDI","TIANZIFANG","WAITAN"};

    @Autowired
    public void setCrowdSituationApiService(CrowdSituationApiService crowdSituationApiService) {
        this.crowdSituationApiService = crowdSituationApiService;
    }


    private HiveZdk57ApiService hiveZdk57ApiService;

    @Autowired
    public void setHiveZdk57ApiService(HiveZdk57ApiService hiveZdk57ApiService) {
        this.hiveZdk57ApiService = hiveZdk57ApiService;
    }

    private GaApiService gaApiService;

    @Autowired
    public void setGaApiService(GaApiService gaApiService) {
        this.gaApiService = gaApiService;
    }


    private QzJjzdApiService qzJjzdApiService;

    @Autowired
    public void setQzJjzdApiService(QzJjzdApiService qzJjzdApiService) {
        this.qzJjzdApiService = qzJjzdApiService;
    }


    private BlmqApiService blmqApiService;

    @Autowired
    public void setBlmqApiService(BlmqApiService blmqApiService) {
        this.blmqApiService = blmqApiService;
    }

    @Resource
    private SyncScenicSpotService syncScenicSpotService;


    @Autowired
    private MetroService metroService;

    @Autowired
    private GongGongAnQuanApiSysDataService gongGongAnQuanApiSysDataService;

    /**
     * 阿里在线点位列表
     */
    @RequestMapping(value = "/getAliOnlineCameraCount")
    public void getAliOnlineCameraCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();


        String content = "";
        Integer size = 0;
        try {
            String url = "http://215.0.0.31:8085/online_camera";
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet get = new HttpGet(url);
            HttpResponse response = httpClient.execute(get);
            content = EntityUtils.toString(response.getEntity());
            JSONArray jsonArray = JSONArray.parseArray(content);
            size = jsonArray.size();
        } catch (IOException e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("data", 0);
            responseData(resultObj.toString(), resp);
            return;
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", size);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 获取南京路点位某个时间点的数据
     */
    @RequestMapping(value = "/getAliPersonDataByListTime")
    public void getAliPersonDataByListTime(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getAliPersonDataByListTime-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        String time = reqjson.getString("time");

        String string = crowdSituationApiService.getListAliPersonCountByTime(time);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", string);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取南京路点位数据
     */
    @RequestMapping(value = "/getAliPersonDataByList")
    public void getAliPersonDataByList(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        String todayZero = DateUtil.getToday23(0, 0, 0);

        List<Map<String, Object>> listString = crowdSituationApiService.getListAliPersonCount(todayZero);

//        List<String> personcount=new ArrayList<String>();
//        String newgps="";
//        JSONArray listarray=new JSONArray();
//        for(String str:listString){
//
//            JSONObject oneJson=new JSONObject();
//            JSONArray oneArray=new JSONArray();
//            if(StringUtil.isNotEmpty(str)){
//                JSONObject json=JSONObject.parseObject(str);
//                String gps=json.getString("gps");
//                newgps= gps.replaceAll("\\[","{");
//                newgps=newgps.replaceAll("\\]","}");
//
////                char[] gpsarray=gps.getScenicStateData
//                JSONArray jsonArray=JSONArray.parseArray(newgps);
//                for(int i=0;i> jsonArray.size();i++){
//                    JSONObject jsonObject=jsonArray.getJSONObject(i);
//                    System.out.println(jsonObject.toString());
////                    oneJson.put("lng",jsonObject.)
//                }
//
//            }
//        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listString);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 获取外滩点位数据
     */
    @RequestMapping(value = "/getAliPersonWtData")
    public void getAliPersonWtData(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        String todayZero = DateUtil.getToday23(0, 0, 0);

        List<Map<String, Object>> listString = crowdSituationApiService.getWtAliPersonCount(todayZero);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listString);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 根据景区编码获取景区周边道路名称（去重）
     *
     * @return json
     */
    @RequestMapping(value = "/getRoadName")
    public void getRoadName(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getRoadName-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        String spotCode = reqjson.getString("spotCode");

        if (spotCode.equalsIgnoreCase("SHHPQ_YUYUAN_NEIQUAN")) {
            spotCode = "SHHPQ_YUYUAN_WAIQUAN";
        }

        List<String> roadName = crowdSituationApiService.getListRoadNameBySpotCode(spotCode);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", roadName);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取景区周边道路信息
     *
     * @return
     */
    @RequestMapping(value = "/getSpotRoadInfoData")
    public void getSpotRoadInfoData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------Dutypeople-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        String spotCode = reqjson.getString("spotCode");


        List<SpotRoadInfo> listSpotRoadInfo = crowdSituationApiService.getListSpotRoadInfoBySpotCode(spotCode);

        for (SpotRoadInfo record : listSpotRoadInfo) {

            int roadLevel = crowdSituationApiService.getSpotRoadLevelByNameAndSpotCode(record.getSpotCode(), record.getRoadName());


            String nostopSpeed = record.getNostopSpeed();
            if (nostopSpeed != null) {
                Double _nostopSpeed = Double.valueOf(nostopSpeed);
                //计算拥堵级别
                //高速公路
                if (roadLevel == 41000) {//高速
                    if (_nostopSpeed > 50) {//畅通
                        record.setConges("畅通");
                    } else if (30 <= _nostopSpeed && _nostopSpeed <= 50) {//缓行
                        record.setConges("缓行");
                    } else if (15 <= _nostopSpeed && _nostopSpeed < 30) {//拥堵
                        record.setConges("拥堵");
                    } else if (15 < _nostopSpeed) {//严重拥堵
                        record.setConges("严重拥堵");
                    }
                } else if (roadLevel == 43000) {//快速路
                    if (_nostopSpeed > 40) {//畅通
                        record.setConges("畅通");
                    } else if (20 <= _nostopSpeed && _nostopSpeed <= 40) {//缓行
                        record.setConges("缓行");
                    } else if (10 <= _nostopSpeed && _nostopSpeed < 20) {//拥堵
                        record.setConges("拥堵");
                    } else if (10 < _nostopSpeed) {//严重拥堵
                        record.setConges("严重拥堵");
                    }
                } else if (roadLevel == 44000) {//主要道路
                    if (_nostopSpeed > 25) {//畅通
                        record.setConges("畅通");
                    } else if (12 <= _nostopSpeed && _nostopSpeed <= 25) {//缓行
                        record.setConges("缓行");
                    } else if (5 <= _nostopSpeed && _nostopSpeed < 12) {//拥堵
                        record.setConges("拥堵");
                    } else if (5 < _nostopSpeed) {//严重拥堵
                        record.setConges("严重拥堵");
                    }
                } else if (roadLevel == 45000) {//次要道路
                    if (_nostopSpeed > 20) {//畅通
                        record.setConges("畅通");
                    } else if (10 <= _nostopSpeed && _nostopSpeed <= 20) {//缓行
                        record.setConges("缓行");
                    } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                        record.setConges("拥堵");
                    } else if (5 < _nostopSpeed) {//严重拥堵
                        record.setConges("严重拥堵");
                    }
                } else {
                    if (_nostopSpeed > 20) {//畅通
                        record.setConges("畅通");
                    } else if (10 <= _nostopSpeed && _nostopSpeed <= 15) {//缓行
                        record.setConges("缓行");
                    } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                        record.setConges("拥堵");
                    } else if (5 < _nostopSpeed) {//严重拥堵
                        record.setConges("严重拥堵");
                    }
                }
            }
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSpotRoadInfo);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取各个景区过去一小时实时人流信息
     *
     * @return
     */
    @RequestMapping(value = "/getCrowdPastHourData")
    public void getCrowdPastHourData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------Dutypeople-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词
        String spotCode = reqjson.getString("spotCode");

        String pastHour = DateUtil.getlastHour(1);


        List<SysRefinedCrowdSituation> listsr = crowdSituationApiService.getSysRefinedCrowdSituationBySpotCodePastHour(spotCode, pastHour);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listsr);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 各个景区最近一小时趋势统计
     * 替换原来（80接口）http://172.82.4.51/crowd/getCrowdPastHourData
     */
    @RequestMapping(value = "/getCrowdPastHourDataNew")
    public void getCrowdPastHourDataNew(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------Dutypeople-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
         Map<String, Object> map = new HashMap<>();
        //热词
        String spotCode = reqjson.getString("spotCode");
        String pastHour = DateUtil.getlastHour(1);
        //获取  SHHPQ_YUYUAN_NEIQUAN,  ---豫园股份
        //南京路： SHHPQ_NANJINGLU,  ---阿里
        // 南京路东拓: SHHPQ_NANJINGLUDONGTUO ---阿里
        //在表sys_refined_crowdSituation_history中
        // String[] spotCodes = {"SHHPQ_YUYUAN_NEIQUAN","SHHPQ_NANJINGLU","SHHPQ_NANJINGLUDONGTUO","SHHPQ_WAITAN_Ali"};
        List<String> spotCodeList = Arrays.asList(spotCodes);
        if(spotCodeList.contains(spotCode)){
            List<SysRefinedCrowdSituation> list = crowdSituationApiService.getSysRefinedCrowdSituationBySpotCodePastHour(spotCode, pastHour);
            if(list != null && list.size() > 0){
                for(SysRefinedCrowdSituation item : list){
                    String minute = DateUtil.getMinute(item.getCreateTime());
                    map.put(minute,item.getRealtimeNumber());
                }
            }
        }
        //获取外滩观景平台、豫园外圈、田子坊、新天地数据 ---客流眼数据
        //在表hp_spot_realtime中;
        //String[] spotIds = {"YUYUAN","XINTIANDI","TIANZIFANG","WAITAN"};
        List<String> spotIdList = Arrays.asList(spotIds);
        if(spotIdList.contains(spotCode)){
            List<HpScenicRealTime> list = syncScenicSpotService.getSpotDataBySpotCodePastHour(spotCode, pastHour);
            if(list != null && list.size() > 0){
                for(HpScenicRealTime item : list){
                    String minute = DateUtil.getMinute(item.getCreateTime());
                    map.put(minute,item.getRealtimenumber());
                }
            }
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", map);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 景区值班人员
     */
    @RequestMapping(value = "/Dutypeople")
    public void Dutypeople(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------Dutypeople-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词
        String scenicpartment = reqjson.getString("scenicpartment");

        List<ScenicAttendant> listScenicAttendant = crowdSituationApiService.getListScenicAttendantByscenicpartment(scenicpartment);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listScenicAttendant);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据BuildID查询问题建筑信息图片
     */
    @RequestMapping(value = "/getErrorBuildInfoImageByBuildId")
    public void getErrorBuildInfoImageByBuildId(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        String name = req.getParameter("name");
        String ip = req.getParameter("ip");
        String namecode = System.currentTimeMillis() + RandomStringUtils.random(4, "1234567890");
        String content = "";
        LogFactory.getLog(this.getClass()).info("------getXiaoGongChengUrlByName-----start-------");
        try {
            String url = "http://11.66.236.1:9903/blmqimage/" + name;
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet get = new HttpGet(url);
            HttpResponse response = httpClient.execute(get);
            HttpEntity entity = response.getEntity();
            try {
                //获取图片存放路径
                String imgPath = "/home/software/HuangpuWebApi/images/" + namecode + ".jpg";
                InputStream inStream = entity.getContent();
                FileOutputStream fw = new FileOutputStream(imgPath, false);
                int b = inStream.read();
                while (b != -1) {
                    fw.write(b);
                    b = inStream.read();
                }
                fw.close();
                EntityUtils.consume(entity);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {

            }
        } catch (IOException e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("data", content);
            responseData(resultObj.toString(), resp);
            return;
        }
//        responseData(content.toString(), resp);
        if (ip != null) {
            resp.sendRedirect("http://10.221.1.168:8080/images/" + namecode + ".jpg");
        } else {
            resp.sendRedirect("http://172.82.4.51:8080/images/" + namecode + ".jpg");
        }

    }


    /**
     * 根据BuildID查询问题建筑信息
     */
    @RequestMapping(value = "/getErrorBuildInfoByBuildId")
    public void getErrorBuildInfoByBuildId(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getErrorBuildInfoByBuildId-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词
        String buildid = reqjson.getString("buildid");


        BlmqBuildInfo blmqBuildInfo = blmqApiService.getBuildInfoByBuildId(buildid);

        BlmqCheckList blmqCheckList = blmqApiService.getBlmqCheckListByBuildId(buildid);

        List<BlmqCheckListDtl> blmqCheckListDtl = blmqApiService.getBlmqCHeckListDtlByCheckListId(blmqCheckList.getID());
        List<BlmqCheckListLog> listCheckListLog = blmqApiService.getListBlmqCheckListLogById(blmqCheckList.getID());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("blmqBuildInfo", blmqBuildInfo);
        jsonObject.put("blmqCheckList", blmqCheckList);
        jsonObject.put("blmqCheckListDtl", blmqCheckListDtl);
        jsonObject.put("listCheckListLog", listCheckListLog);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonObject);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据BuildID 查询BuildINFO 信息
     */
    @RequestMapping(value = "/getBuildInfoByBuildId")
    public void getBuildInfoByBuildId(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getBuildInfoByBuildId-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词
        String buildid = reqjson.getString("buildid");

        BlmqBuildInfo blmqBuildInfo = blmqApiService.getBuildInfoByBuildId(buildid);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", blmqBuildInfo);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据景区编码获取单个景区详情(南京路，外滩)
     *
     * @return json
     */
    @RequestMapping(value = "/getScenicStateData")
    public void getScenicStateData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getScenicStateData-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String spotCode = reqjson.getString("spotCode");
        SysHpScenicState ss = crowdSituationApiService.getSysHpScenicStateBySpotCode(spotCode);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ss);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 玻璃幕墙事件推送
     */
    @RequestMapping(value = "/getBlmqGlassEventPush")
    public void getBlmqGlassEventPush(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();


        LogFactory.getLog(this.getClass()).info("------getBlmqGlassEventPush-----start-------");
//        BlmqCheckListLog blmqCheckListLog = new BlmqCheckListLog();
        List<BlmqCheckList> listBlmqCheckList = blmqApiService.getListBlmqCheckList();
//        List<BlmqCheckListLog> listBlmqCheckListLog = blmqApiService.getListBlmqCheckListLog();

        for (BlmqCheckList bllog : listBlmqCheckList) {
            JSONObject jsonObject = new JSONObject();
            if (bllog.getNEED_CHANGE() == 1) {
                BlmqCheckListLog blmqCheckListLog = blmqApiService.getBlmqCheckListLogById(bllog.getID());
                jsonObject.put("blmqCheckListLog", blmqCheckListLog);
            } else {
                jsonObject.put("blmqCheckListLog", "");
            }
            BlmqBuildInfo blmqBuildInfo = blmqApiService.getBuildInfoByBuildId(bllog.getBUILD_ID() + "");
            if(blmqBuildInfo == null){
                blmqBuildInfo = new BlmqBuildInfo();
            }
            List<BlmqCheckListDtl> listBlmqCheckListDtl = blmqApiService.getBlmqCHeckListDtlByCheckListId(bllog.getID());
            if (listBlmqCheckListDtl.size() > 1) {
                jsonObject.put("name", listBlmqCheckListDtl.get(0).getDAMAGE_TYPE());
            } else {
                jsonObject.put("name", "");
            }
            jsonObject.put("buildid", blmqBuildInfo.getBUILD_ID());
            jsonObject.put("buildname", blmqBuildInfo.getBUILD_NAME());
            jsonObject.put("need_change", bllog.getNEED_CHANGE());
            jsonObject.put("high_deop_risk", bllog.getHIGH_DEOP_RISK());
            jsonObject.put("street", blmqBuildInfo.getVILLAGE());
            jsonObject.put("owenername", blmqBuildInfo.getOWNER_NAME());
            jsonObject.put("createtime", bllog.getCHECK_TIME());


            double[] map = MapUtil.bd09towgs84(Double.parseDouble(blmqBuildInfo.getLONGITUDE() + ""), Double.parseDouble(blmqBuildInfo.getLATITUDE() + ""));
            jsonObject.put("lng", map[0] + "");
            jsonObject.put("lat", map[1] + "");
            jsonArray.add(jsonObject);
//            jsonObject.put("BlmqCheckListLog",blmqCheckListLog);
//            jsonObject.put("blmqCheckList",bllog);
//            jsonObject.put("blmqBuildInfo",blmqBuildInfo);
//            jsonObject.put("listBlmqCheckListDtl",listBlmqCheckListDtl);
//            jsonArray.add(jsonObject);
        }

//        for (BlmqCheckListLog bllog : listBlmqCheckListLog) {
//            jsonObject = new JSONObject();
        // BlmqCheckListLog blmqCheckListLog=blmqApiService.getBlmqCheckListLogById(bllog.getID());
//            BlmqCheckList bc = blmqApiService.getBlmqCheckListById(bllog.getCHECK_LISE_ID());
//            BlmqBuildInfo blmqBuildInfo = blmqApiService.getBuildInfoByBuildId(bc.getBUILD_ID() + "");
//            List<BlmqCheckListDtl> listBlmqCheckListDtl = blmqApiService.getBlmqCHeckListDtlByCheckListId(bllog.getCHECK_LISE_ID());
//            jsonObject.put("BlmqCheckListLog",bllog);
//            jsonObject.put("blmqCheckList",bc);
//            jsonObject.put("blmqBuildInfo",blmqBuildInfo);
//            jsonObject.put("listBlmqCheckListDtl",listBlmqCheckListDtl);

//            if (listBlmqCheckListDtl.size() > 1) {
//                jsonObject.put("name", listBlmqCheckListDtl.get(0).getDAMAGE_TYPE());
//            } else {
//                jsonObject.put("name", "");
//            }
//            jsonObject.put("buildid", blmqBuildInfo.getBUILD_ID());
//            jsonObject.put("buildname", blmqBuildInfo.getBUILD_NAME());
//            jsonObject.put("street", blmqBuildInfo.getVILLAGE());
//            jsonObject.put("owenername", blmqBuildInfo.getOWNER_NAME());
//            jsonObject.put("createtime", bllog.getFIND_TIME());
//            double[] map = MapUtil.bd09towgs84(Double.parseDouble(blmqBuildInfo.getLONGITUDE() + ""), Double.parseDouble(blmqBuildInfo.getLATITUDE() + ""));
//            jsonObject.put("lng", map[0] + "");
//            jsonObject.put("lat", map[1] + "");
//            jsonArray.add(jsonObject);
//        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);

        responseData(resultObj.toString(), resp);
    }

    /**
     * 玻璃幕墙检查情况-业主自查
     */
    @RequestMapping(value = "/getBlmqGlassCheckOwn")
    public void getBlmqGlassCheckOwn(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();


        LogFactory.getLog(this.getClass()).info("------getBlmqGlassCheckOwn-----start-------");

        //业主自查
        Integer ownhassubmit = blmqApiService.getOwnHasSubmitCount();
        //问题
        Integer ownhaserror = blmqApiService.getOwnHasErrorCount();
        //填报率
        double ownhassubmitpercent = (double) ownhassubmit / 603;
        //问题率
        double ownhaserrorpercent = (double) ownhaserror / 603;


        Integer OPERABLE_VENTCount = blmqApiService.getOperableVentCount();
        Integer SEALANTCount = blmqApiService.getSEALANTCount();
        Integer GLASSCount = blmqApiService.getGLASSCount();
        Integer FORCE_MEMBERCount = blmqApiService.getFORCE_MEMBERCount();
        Integer RAINCount = blmqApiService.getRainCount();

        JSONArray dataarray = new JSONArray();
        JSONObject datajson = new JSONObject();
        datajson.put("year", "2019");
        datajson.put("ownhassubmitpercent", "17.41%");
        datajson.put("ownhaserrorpercent", "35.45%");
        dataarray.add(datajson);
        datajson = new JSONObject();
        datajson.put("year", "2020");
        datajson.put("ownhassubmitpercent", Math.round(ownhassubmitpercent * 100) + "%");
        datajson.put("ownhaserrorpercent", Math.round(ownhaserrorpercent * 100) + "%");
        dataarray.add(datajson);
        jsonObject.put("ownhassubmit", ownhassubmit);
        jsonObject.put("ownhassubmitpercent", Math.round(ownhassubmitpercent * 100) + "%");
        jsonObject.put("ownhaserrorpercent", Math.round(ownhaserrorpercent * 100) + "%");
        jsonObject.put("2019ownhassubmitpercent", "17.41%");
        jsonObject.put("2019ownhaserrorpercent", "35.45%");
        jsonObject.put("OPERABLE_VENTCount", OPERABLE_VENTCount);
        jsonObject.put("SEALANTCount", SEALANTCount);
        jsonObject.put("GLASSCount", GLASSCount);
        jsonObject.put("FORCE_MEMBERCount", FORCE_MEMBERCount);
        jsonObject.put("RAINCount", RAINCount);
        jsonObject.put("dataarray", dataarray);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonObject);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 玻璃幕墙检查情况-区巡查
     */
    @RequestMapping(value = "/getBlmqGlassCheckQu")
    public void getBlmqGlassCheckQu(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject jsonObject = new JSONObject();


        LogFactory.getLog(this.getClass()).info("------getBlmqGlassCheckQu-----start-------");

        //获取区检查
        //区已巡查
        Integer quhascheck = blmqApiService.getQuHasCheckCount();
        //区应整改
        Integer quhaschange = blmqApiService.getQuHasChangeCount();
        //区已结案
        Integer quhasend = quhascheck - quhaschange;


        //各街道检查情况
        List<String> liststreet = blmqApiService.getListStreet();
        JSONArray jsonArray = new JSONArray();
        JSONObject streetjson = null;
        for (String street : liststreet) {

            //获取该街道下所有幕墙数据
            List<String> listStreetBuildId = blmqApiService.getListStreetBuileId(street);
            int streetquhascheck = 0;
            int streetquhasnocheck = 0;
            int streetquhaschange = 0;
            int streetquhasnochange = 0;
            for (String st : listStreetBuildId) {
                Integer CHECK_STATUS = blmqApiService.getCheckStatusByBuildId(st);
                //检查状态（0：未检，1：已检）
                if (CHECK_STATUS == 0) {
                    streetquhasnocheck = streetquhasnocheck + 1;
                } else {
                    streetquhascheck = streetquhascheck + 1;
                }

                Integer NEED_CHANGE = blmqApiService.getNeedChangeByBuildId(st);
                if (NEED_CHANGE == 0) {
                    streetquhaschange = streetquhaschange + 1;
                } else {
                    streetquhasnochange = streetquhasnochange + 1;
                }

            }


            streetjson = new JSONObject();
            streetjson.put("street", street);
            streetjson.put("streetquhascheck", streetquhascheck);
            streetjson.put("streetquhasnocheck", streetquhasnocheck);
            streetjson.put("streetquhaschange", streetquhaschange);
            streetjson.put("streetquhasnochange", streetquhasnochange);
            jsonArray.add(streetjson);


        }
        //区巡检异常问题分析
        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = blmqApiService.getListBlmqCheckErrorType();


        jsonObject.put("errortypelist", listSysHpXiaoFangAjType);
        jsonObject.put("quhascheck", quhascheck);
        jsonObject.put("quhaschange", quhaschange);
        jsonObject.put("ownhaserrorpercent", quhasend);
        jsonObject.put("jsonArray", jsonArray);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonObject);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 玻璃幕墙检查情况
     */
    @RequestMapping(value = "/getBlmqGlassCheck")
    public void getBlmqGlassCheck(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String year = reqjson.getString("year");
        LogFactory.getLog(this.getClass()).info("------getBlmqSize-----start-------");


        //获取市检查
        BlmqCountryCheck blmqCountryCheck = blmqApiService.getBlmqCountryCheck(year);


        jsonObject.put("blmqCountryCheck", blmqCountryCheck);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonObject);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 玻璃构造
     */
    @RequestMapping(value = "/getBlmqGlassSTRUCTURE")
    public void getBlmqGlassSTRUCTURE(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;


        LogFactory.getLog(this.getClass()).info("------getBlmqSize-----start-------");


        //无框
        Integer count = blmqApiService.getBlmqGlassSTRUCTURE("无框");
        jsonObject = new JSONObject();
        jsonObject.put("name", "无框");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //隐框
        count = blmqApiService.getBlmqGlassSTRUCTURE("隐框");
        jsonObject = new JSONObject();
        jsonObject.put("name", "隐框");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //半隐框
        count = blmqApiService.getBlmqGlassSTRUCTURE("半隐框");
        jsonObject = new JSONObject();
        jsonObject.put("name", "半隐框");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //明框
        count = blmqApiService.getBlmqGlassSTRUCTURE("明框");
        jsonObject = new JSONObject();
        jsonObject.put("name", "明框");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //其他
        count = blmqApiService.getBlmqGlassSTRUCTURE("");
        jsonObject = new JSONObject();
        jsonObject.put("name", "其他");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 玻璃类型
     */
    @RequestMapping(value = "/getBlmqGlassType")
    public void getBlmqGlassType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;


        LogFactory.getLog(this.getClass()).info("------getBlmqGlassType-----start-------");


        //单层玻璃
        Integer count = blmqApiService.getBlmqGlassType("单层玻璃");
        jsonObject = new JSONObject();
        jsonObject.put("name", "单层玻璃");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //夹层玻璃
        count = blmqApiService.getBlmqGlassType("夹层玻璃");
        jsonObject = new JSONObject();
        jsonObject.put("name", "夹层玻璃");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //夹层中空玻璃
        count = blmqApiService.getBlmqGlassType("夹层中空玻璃");
        jsonObject = new JSONObject();
        jsonObject.put("name", "夹层中空玻璃");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);
        //中空玻璃
        count = blmqApiService.getBlmqGlassType("中空玻璃");
        jsonObject = new JSONObject();
        jsonObject.put("name", "中空玻璃");
        jsonObject.put("count", count);
        jsonArray.add(jsonObject);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 玻璃类型数据列表
     */
    @RequestMapping(value = "/getBlmqGlassSTRUCTUREByType")
    public void getBlmqGlassSTRUCTUREByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getBlmqSizeByType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词 无框 隐框 半隐框 明框 其他
        String type = reqjson.getString("type");

        List<Integer> listSize = blmqApiService.getBlmqGlassSTRUCTUREByType(type);

        List<String> listBlmqBuildInfo = new ArrayList<String>();
        for (Integer size : listSize) {
            BlmqBuildInfo bl = blmqApiService.getBuildInfoByBuildId(size + "");
            listBlmqBuildInfo.add(bl.getBUILD_ID() + "");

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listBlmqBuildInfo);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 玻璃类型数据列表
     */
    @RequestMapping(value = "/getBlmqGlassTypeByType")
    public void getBlmqGlassTypeByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getBlmqSizeByType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词 单层玻璃 夹层玻璃 夹层中空玻璃 中空玻璃
        String type = reqjson.getString("type");

        List<Integer> listSize = blmqApiService.getListBuildidBlmqBlmqGlassType(type);

        List<String> listBlmqBuildInfo = new ArrayList<String>();
        for (Integer size : listSize) {
            BlmqBuildInfo bl = blmqApiService.getBuildInfoByBuildId(size + "");
            listBlmqBuildInfo.add(bl.getBUILD_ID() + "");

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listBlmqBuildInfo);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 幕墙面积数据列表
     */
    @RequestMapping(value = "/getBlmqSizeByType")
    public void getBlmqSizeByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getBlmqSizeByType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词 10000 5000  1000 500
        String type = reqjson.getString("type");

        List<Integer> listSize = blmqApiService.getListBuildidBlmqSize(type);
        List<String> listBlmqBuildInfo = new ArrayList<String>();
        for (Integer size : listSize) {
            BlmqBuildInfo bl = blmqApiService.getBuildInfoByBuildId(size + "");
            listBlmqBuildInfo.add(bl.getBUILD_ID() + "");

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listBlmqBuildInfo);
        responseData(resultObj.toString(), resp);


    }


    /**
     * 幕墙面积
     */
    @RequestMapping(value = "/getBlmqSize")
    public void getBlmqSize(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject datajson = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;


        LogFactory.getLog(this.getClass()).info("------getBlmqSize-----start-------");
        Integer allcount = blmqApiService.getBlmqSizeAllCount();
        List<Integer> listSize = blmqApiService.getListBlmqSize();
        //>10000
        int a = 0;
        //5000-10000
        int b = 0;
        //1000-5000
        int c = 0;
        //<1000
        int d = 0;

        for (Integer size : listSize) {

            if (size <= 1000) {
                d = d + 1;
            } else if (size <= 5000) {
                c = c + 1;
            } else if (size <= 10000) {
                b = b + 1;
            } else {
                a = a + 1;
            }

        }

        jsonObject = new JSONObject();
        jsonObject.put("name", ">10000");
        jsonObject.put("count", a);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        double percent = (double) a / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("name", "5000-10000");
        jsonObject.put("count", b);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) b / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        jsonObject = new JSONObject();
        jsonObject.put("name", "1000-5000");
        jsonObject.put("count", c);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) c / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        jsonObject = new JSONObject();
        jsonObject.put("name", "<1000");
        jsonObject.put("count", d);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) d / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 幕墙高度
     */
    @RequestMapping(value = "/getBlmqHeight")
    public void getBlmqHeight(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject datajson = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;


        LogFactory.getLog(this.getClass()).info("------getBlmqHeight-----start-------");
        Integer allcount = blmqApiService.getBlmqHeightAllCount();
        List<Integer> listHeight = blmqApiService.getListBlmqHeight();
        //>300
        int a = 0;
        //100-300
        int b = 0;
        //24-100
        int c = 0;
        //<24
        int d = 0;

        for (Integer height : listHeight) {

            if (height <= 24) {
                d = d + 1;
            } else if (height <= 100) {
                c = c + 1;
            } else if (height <= 300) {
                b = b + 1;
            } else {
                a = a + 1;
            }

        }

        jsonObject = new JSONObject();
        jsonObject.put("name", "300m以上");
        jsonObject.put("count", a);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        double percent = (double) a / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("name", "100m-300m");
        jsonObject.put("count", b);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) b / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        jsonObject = new JSONObject();
        jsonObject.put("name", "24m-100m");
        jsonObject.put("count", c);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) c / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        jsonObject = new JSONObject();
        jsonObject.put("name", "24m以下");
        jsonObject.put("count", d);
        //Math.round()
        //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
        percent = (double) d / allcount;
        jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
        jsonArray.add(jsonObject);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 幕墙健康水平分级
     */
    @RequestMapping(value = "/getBlmqUseNatureLevel")
    public void getBlmqUseNatureLevel(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject datajson = new JSONObject();
        JSONObject jsonObject = new JSONObject();


        LogFactory.getLog(this.getClass()).info("------getBlmqUseNatureLevel-----start-------");

        List<BlmqBuildInfoLevel> listBlmqBuildInfoLevel = blmqApiService.getListBlmqBuildInfoLevel();

        int A = 0;
        int B = 0;
        int C = 0;
        for (BlmqBuildInfoLevel binfo : listBlmqBuildInfoLevel) {

            if (binfo.getBUILDING_SORT().equals("A")) {
                A = A + 1;
            }

            if (binfo.getBUILDING_SORT().equals("B")) {
                B = B + 1;
            }
            if (binfo.getBUILDING_SORT().equals("C")) {
                C = C + 1;
            }


        }
        jsonObject.put("A", A);
        jsonObject.put("B", B);
        jsonObject.put("C", C);


        List<String> liststreet = blmqApiService.getListStreet();
        JSONArray jsonArray = new JSONArray();
        JSONObject streetjson = null;
        for (String street : liststreet) {

            List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = blmqApiService.getListBlmqStreetLevel(street);
            for (SysHpXiaoFangAjType st : listSysHpXiaoFangAjType) {
                streetjson = new JSONObject();
                streetjson.put("street", street);
                streetjson.put("name", st.getName());
                streetjson.put("count", st.getCount());
                jsonArray.add(streetjson);
            }


        }


        datajson.put("alljson", jsonObject);
        datajson.put("streetjson", jsonArray);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", datajson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 幕墙使用场景排行
     */
    @RequestMapping(value = "/getBlmqUseNatureOrderDesc")
    public void getBlmqUseNatureOrderDesc(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getBlmqUseNatureOrderDesc-----start-------");


        Integer allcount = blmqApiService.getBlmqAllCount();


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = blmqApiService.getBlmqGroupUseNature();
        List<BlmqBuildInfoGroup> listBlmqBuildInfoGroup = new ArrayList<BlmqBuildInfoGroup>();
        //多用途建筑
        int countnum = 0;
        BlmqBuildInfoGroup bg = null;
        for (SysHpXiaoFangAjType sy : listSysHpXiaoFangAjType) {
            if (sy.getName().indexOf(",") != -1) {
                countnum = countnum + 1;
            } else {
                bg = new BlmqBuildInfoGroup();
                bg.setName(sy.getName());
                bg.setCount(Integer.parseInt(sy.getCount()));
                listBlmqBuildInfoGroup.add(bg);
            }
        }
        bg = new BlmqBuildInfoGroup();
        bg.setName("多用途建筑");
        bg.setCount(countnum);
        listBlmqBuildInfoGroup.add(bg);
        Collections.sort(listBlmqBuildInfoGroup); // 按年龄排序


        for (BlmqBuildInfoGroup bginfo : listBlmqBuildInfoGroup) {

            jsonObject = new JSONObject();
            jsonObject.put("name", bginfo.getName());
            jsonObject.put("count", bginfo.getCount());
            double percent = (double) bginfo.getCount() / allcount;
            jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
            jsonArray.add(jsonObject);


        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 警情热词数据获取接口
     */
    @RequestMapping(value = "/getXiaofangKeyString")
    public void getXiaofangKeyString(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getXiaofangKeyString-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //热词
        String keystring = reqjson.getString("keystring");
        List<SysHpXiaoFangAj> listSysHpXiaoFangAj = crowdSituationApiService.getListSysHpXiaoFangAjKeyString(keystring);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysHpXiaoFangAj);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 警情热力效果接口
     */
    @RequestMapping(value = "/getXiaofangAjHotAreaData")
    public void getXiaofangAjHotAreaData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangAjAreaData-----start-------");


        JSONObject stationjson = new JSONObject();
        stationjson.put("name", "外滩站");
        double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.510956"), Double.parseDouble("31.226916"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("外滩站");
        JSONArray stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "车站站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.477928"), Double.parseDouble("31.211223"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("车站站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "北京站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.477928"), Double.parseDouble("31.242358"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("北京站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "河南站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.487746"), Double.parseDouble("31.243108"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("河南站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "复兴站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.493208"), Double.parseDouble("31.221296"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("复兴站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "嵩山站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.483151"), Double.parseDouble("31.229824"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("嵩山站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        stationjson = new JSONObject();
        stationjson.put("name", "卢湾站");
        map = MapUtil.bd09towgs84(Double.parseDouble("121.489827"), Double.parseDouble("31.205869"));
        stationjson.put("lng", map[0] + "");
        stationjson.put("lat", map[1] + "");


        listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation("卢湾站");
        stationArray = new JSONArray();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());

            stationArray.add(jsonObject);
        }
        stationjson.put("typearray", stationArray);

        jsonArray.add(stationjson);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 警情冰山效果接口
     */
    @RequestMapping(value = "/getXiaofangAjAreaData")
    public void getXiaofangAjAreaData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangAjAreaData-----start-------");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getListSysHpXiaoFangAjAreaData();


        List<SysHpXiaoFangAjType> newlistSysHpXiaoFangAjType = new ArrayList<SysHpXiaoFangAjType>();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            if (StringUtil.isEmpty(sj.getName())) {
                continue;
            }


            if (sj.getName().equals("外滩站")) {

                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.510956"), Double.parseDouble("31.226916"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.510956");
//                sj.setLat("31.226916");
                newlistSysHpXiaoFangAjType.add(sj);
            }

            if (sj.getName().equals("车站站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.499934"), Double.parseDouble("31.211223"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.499934");
//                sj.setLat("31.211223");
                newlistSysHpXiaoFangAjType.add(sj);
            }

            if (sj.getName().equals("北京站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.477928"), Double.parseDouble("31.242358"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.477928");
//                sj.setLat("31.242358");
                newlistSysHpXiaoFangAjType.add(sj);
            }


            if (sj.getName().equals("河南站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.487746"), Double.parseDouble("31.243108"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.487746");
//                sj.setLat("31.243108");
                newlistSysHpXiaoFangAjType.add(sj);
            }


            if (sj.getName().equals("复兴站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.493208"), Double.parseDouble("31.221296"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.493208");
//                sj.setLat("31.221296");
                newlistSysHpXiaoFangAjType.add(sj);
            }

            if (sj.getName().equals("嵩山站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.483151"), Double.parseDouble("31.229824"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.483151");
//                sj.setLat("31.229824");
                newlistSysHpXiaoFangAjType.add(sj);
            }

            if (sj.getName().equals("卢湾站")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.489827"), Double.parseDouble("31.205869"));
                sj.setLng(map[0] + "");
                sj.setLat(map[1] + "");
//                sj.setLng("121.489827");
//                sj.setLat("31.205869");
                newlistSysHpXiaoFangAjType.add(sj);
            }


        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", newlistSysHpXiaoFangAjType);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 单个警局消防警情分析
     */
    @RequestMapping(value = "/getXiaofangTypeDataByStation")
    public void getXiaofangTypeDataByStation(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;
        String str = getRequestBodyString(req);
        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangTypeDataByStation-----start-------");


        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String keystring = reqjson.getString("keystring");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjTypeStation(keystring);
        int allcount = crowdSituationApiService.getXiaoFangAllCountStation(keystring);
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());
            //Math.round()
            //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
            double percent = (double) Integer.parseInt(sj.getCount()) / allcount;
            jsonObject.put("percent", Math.round(percent * 100) + "%");
            jsonArray.add(jsonObject);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 消防站警情分析
     */
    @RequestMapping(value = "/getXiaofangAjDataByStation")
    public void getXiaofangAjDataByStation(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getXiaofangAjDataByStation-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String keystring = reqjson.getString("keystring");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getListSysHpXiaoFangAjTypeStation(keystring);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysHpXiaoFangAjType);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 消防警情类型热词分析
     */
    @RequestMapping(value = "/getXiaofangKeyData")
    public void getXiaofangKeyData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getXiaofangKeyData-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String keystring = reqjson.getString("keystring");

        JSONObject retrunjsonobject = new JSONObject();
        List<SysHpXiaoFangAjTypeHour> listSysHpXiaoFangAjTypeHour = crowdSituationApiService.getListlistSysHpXiaoFangAjTypeHour(keystring);
        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjTypeMonth = crowdSituationApiService.getListSysHpXiaoFangAjMonthData(keystring);

        int maxmonth = 0;
        int maxhour = 0;
        String maxmonthtime = "0";
        String maxhourtime = "0";

        for (SysHpXiaoFangAjTypeHour sj : listSysHpXiaoFangAjTypeHour) {
            if (Integer.parseInt(sj.getCount()) > maxhour) {
                maxhour = Integer.parseInt(sj.getCount());
                maxhourtime = sj.getHour();
            }
        }


        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjTypeMonth) {
            if (Integer.parseInt(sj.getCount()) > maxmonth) {
                maxmonth = Integer.parseInt(sj.getCount());
                maxmonthtime = sj.getName();
            }
        }

        retrunjsonobject.put("montharray", listSysHpXiaoFangAjTypeMonth);
        retrunjsonobject.put("hourarray", listSysHpXiaoFangAjTypeHour);
        retrunjsonobject.put("maxmonth", maxmonthtime);
        retrunjsonobject.put("maxhour", maxhourtime);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", retrunjsonobject);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 消防警情类型热点事件热词分析
     */
    @RequestMapping(value = "/getXiaofangTypeDetailData")
    public void getXiaofangTypeDetailData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangTypeDetailData-----start-------");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjType();
        int allcount = crowdSituationApiService.getXiaoFangAllCount();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());

            List<SysHpXiaoFangAjType> listKeyString = crowdSituationApiService.getXiaoFangAjTypeKeyString(sj.getName());
            List<String> listString = new ArrayList<String>();
            for (SysHpXiaoFangAjType keysj : listKeyString) {
                listString.add(keysj.getName());
            }
            jsonObject.put("keystring", listString);
            jsonArray.add(jsonObject);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 消防警情类型分析-年度
     */
    @RequestMapping(value = "/getXiaofangTypeDataForYear")
    public void getXiaofangTypeDataForYear(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangTypeDataForYear-----start-------");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjType();
        int allcount = crowdSituationApiService.getXiaoFangAllCount();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());
            JSONArray yearjsonArray = new JSONArray();
            JSONObject yearjsonObject = new JSONObject();
            Integer count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2015-01-01 00:00:00", "2015-12-31 24:59:59");
            yearjsonObject.put("year", "2015");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2016-01-01 00:00:00", "2016-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonObject.put("year", "2016");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2017-01-01 00:00:00", "2017-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonObject.put("year", "2017");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2018-01-01 00:00:00", "2018-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonObject.put("year", "2018");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2019-01-01 00:00:00", "2019-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonObject.put("year", "2019");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2020-01-01 00:00:00", "2020-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonArray.add(yearjsonObject);
            yearjsonObject.put("year", "2020");
            yearjsonObject.put("count", count);
            count = crowdSituationApiService.getXiaoFangKeyStringCountYearType(sj.getName(), "2021-01-01 00:00:00", "2021-12-31 24:59:59");
            yearjsonObject = new JSONObject();
            yearjsonObject.put("year", "2021");
            yearjsonObject.put("count", count);
            yearjsonArray.add(yearjsonObject);
            jsonObject.put("dataarray", yearjsonArray);
            jsonArray.add(jsonObject);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 获取近5年警情数（不分类型，每年）以及本年消防警情类型警情数的接口
     */
    @RequestMapping("/policeInfo")
    @ResponseBody
    public Object getPoliceInfo(){
        JSONObject resultObject = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        //获取近五年数据量
        List<YearCount> yearCountList = crowdSituationApiService.getPoliceInfoCountGroupByYear();
        //获取当年消防情景类型的警情数
        List<PoliceInfoTypeCount> policeInfoTypeCountList = crowdSituationApiService.getPoliceInfoCountGroupByType();
        jsonObject.put("yearCountList", yearCountList);
        jsonObject.put("typeCountList", policeInfoTypeCountList);
        resultObject.put("error_code", 0);
        resultObject.put("error_msg", "获取成功");
        resultObject.put("data", jsonObject);
        return resultObject;
    }


    /**
     * 消防警情类型分析
     */
    @RequestMapping(value = "/getXiaofangTypeData")
    public void getXiaofangTypeData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangTypeData-----start-------");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getHpXiaoFangAjType();
        int allcount = crowdSituationApiService.getXiaoFangAllCount();
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());
            //Math.round()
            //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
            double percent = (double) Integer.parseInt(sj.getCount()) / allcount;
            jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
            jsonArray.add(jsonObject);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 按照年对消防警情类型分析(提供华为接口)
     */
    @RequestMapping(value = "/getXiaofangTypeDataByYear")
    public void getXiaofangTypeDataByYear(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = null;

        JSONArray jsonArray = new JSONArray();
        String year = req.getParameter("year");
        LogFactory.getLog(this.getClass()).info("------getXiaofangTypeDataByYear-----start-------");


        List<SysHpXiaoFangAjType> listSysHpXiaoFangAjType = crowdSituationApiService.getXiaofangTypeDataByYear(year);
        int allcount = crowdSituationApiService.getXiaoFangAllCountByYear(year);
        for (SysHpXiaoFangAjType sj : listSysHpXiaoFangAjType) {
            jsonObject = new JSONObject();
            jsonObject.put("name", sj.getName());
            jsonObject.put("count", sj.getCount());
            //Math.round()
            //System.out.println("Integer.parseInt(sj.getCount())------"+Integer.parseInt(sj.getCount())+"-allcount--"+allcount+Integer.parseInt(sj.getCount()) / allcount);
            double percent = (double) Integer.parseInt(sj.getCount()) / allcount;
            jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
            jsonArray.add(jsonObject);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 消防警情数据总榄
     */
    @RequestMapping(value = "/getXiaofangData")
    public void getXiaofangData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = new JSONObject();

        LogFactory.getLog(this.getClass()).info("------getXiaofangData-----start-------");
        jsonObject.put("monthdata", crowdSituationApiService.getXiaoFangMonthCount()+"");
        jsonObject.put("daydata", crowdSituationApiService.getXiaoFangDayCount()+"");

        Integer yeardata = crowdSituationApiService.getXiaoFangYearCount();
        jsonObject.put("yeardata", yeardata + "");
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonObject);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 消防年度事件数据总览
     */
    @RequestMapping(value = "/getXiaofangYearData")
    public void getXiaofangYearData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        JSONObject jsonObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();

        LogFactory.getLog(this.getClass()).info("------getXiaofangYearData-----start-------");

        jsonObject.put("year", "2015");
        jsonObject.put("count", 2220);
        jsonArray.add(jsonObject);
        jsonObject = new JSONObject();
        jsonObject.put("year", "2016");
        jsonObject.put("count", 2334);
        jsonArray.add(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("year", "2017");
        jsonObject.put("count", 2131);
        jsonArray.add(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("year", "2018");
        jsonObject.put("count", 1491);
        jsonArray.add(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("year", "2019");
        jsonObject.put("count", 1161);
        jsonArray.add(jsonObject);

        Integer yeardata = crowdSituationApiService.getXiaoFangYearCount();

        jsonObject = new JSONObject();
        jsonObject.put("year", "2020");
        jsonObject.put("count", yeardata);
        jsonArray.add(jsonObject);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     *
     */
    @RequestMapping(value = "/getHpTest")
    public void getHpTest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getHpTest-----start-------");

        List<SysHpTest> listSysHptest = crowdSituationApiService.getListSysHpTest();

        for (SysHpTest sh : listSysHptest) {

            double[] map = MapUtil.bd09towgs84(Double.parseDouble(sh.getLng()), Double.parseDouble(sh.getLat()));
            sh.setLng(map[0] + "");
            sh.setLat(map[1] + "");

        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysHptest);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取全区视频信息-老西门街道
     */
    @RequestMapping(value = "/getAllhpPublicVideoListByStreet")
    public void getAllhpPublicVideoListByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        List<SysHpPublicVideo> newlistSysHpPublicVideo = new ArrayList<SysHpPublicVideo>();
        SysHpPublicVideo sv = new SysHpPublicVideo();
        sv.setVideo_name("蓬莱/中华3HG");
        sv.setVideo_device_coding("31010118001180008016");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("经侦信访接待处HRG");
        sv.setVideo_device_coding("31010118001181012015");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("文庙/河南2HG");
        sv.setVideo_device_coding("31010118001180004020");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("蓬莱/河南1HG");
        sv.setVideo_device_coding("31010118001180002005");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("大吉/西藏HG");
        sv.setVideo_device_coding("31010118001180003006");
        newlistSysHpPublicVideo.add(sv);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", newlistSysHpPublicVideo);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 获取全区视频信息-老西门街道
     */
    @RequestMapping(value = "/getAllhpPublicVideoByStreet")
    public void getAllhpPublicVideoByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getAllhpPublicVideo-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        int page = reqjson.getInteger("page");

        List<SysHpPublicVideo> listSysHpPublicVideo = crowdSituationApiService.getRoadIdsFromHpPublicVideoByStreet(page, Constants.GOODSPAGESIZE);

        List<SysHpPublicVideo> newlistSysHpPublicVideo = new ArrayList<SysHpPublicVideo>();
        SysHpPublicVideo sv = new SysHpPublicVideo();
        sv.setVideo_name("蓬莱/中华3HG");
        sv.setVideo_device_coding("31010118001180008016");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("经侦信访接待处HRG");
        sv.setVideo_device_coding("31010118001181012015");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("文庙/河南2HG");
        sv.setVideo_device_coding("31010118001180004020");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("蓬莱/河南1HG");
        sv.setVideo_device_coding("31010118001180002005");
        newlistSysHpPublicVideo.add(sv);
        sv = new SysHpPublicVideo();
        sv.setVideo_name("大吉/西藏HG");
        sv.setVideo_device_coding("31010118001180003006");
        newlistSysHpPublicVideo.add(sv);
        newlistSysHpPublicVideo.addAll(listSysHpPublicVideo);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", newlistSysHpPublicVideo);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 获取全区视频信息
     */
    @RequestMapping(value = "/getAllhpPublicVideo")
    public void getAllhpPublicVideo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getAllhpPublicVideo-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        int page = reqjson.getInteger("page");

        List<SysHpPublicVideo> listSysHpPublicVideo = crowdSituationApiService.getRoadIdsFromHpPublicVideo(page, Constants.GOODSPAGESIZE);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysHpPublicVideo);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 获取全区公安警情数据
     */
    @RequestMapping(value = "/getAllDataInfoByGaJq")
    public void getAllDataInfoByGaJq(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;
        LogFactory.getLog(this.getClass()).info("------getAllDataInfoByGaJq-----start-------");
        List<GaJq> listGajq = gaApiService.getListGaJq(DateUtil.getTodayZero());
        Integer allnum = gaApiService.getGaJqAllNum(DateUtil.getTodayZero());
        GaJq allga = new GaJq();
        allga.setLb("总量");
        allga.setNum(allnum);
        listGajq.add(allga);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listGajq);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 获取全区公安警力数据
     */
    @RequestMapping(value = "/getAllDataInfoByGaJl")
    public void getAllDataInfoByGaJl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getAllDataInfoByGaJl-----start-------");

        List<GaJl> listGajl = gaApiService.getListGaJl();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listGajl);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 人群态势感知-道路预测
     */
    @RequestMapping(value = "/getRoadPredData")
    public void getRoadPredData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getRoadPredData-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        //范围名称
        String roadName = reqjson.getString("roadName");


        String roadId = crowdSituationApiService.getRoadIdByRoadName(roadName);

        String dataTimeStamp = DateUtil.getDateTimeStamp();


        List<QzJJZDRidPredShort> listQzJJZDRidPredShort = qzJjzdApiService.getListQzJJZDRidPredShort(roadId, dataTimeStamp);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listQzJJZDRidPredShort);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取全区公安LBS数据
     */
    @RequestMapping(value = "/getAllDataInfoByLBS")
    public void getAllDataInfoByLBS(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getAllDataInfoByLBS-----start-------");
//        if (StringUtil.isEmpty(str)) {
//            responseErrorData("json error", resp);
//            return;
//        }
//        JSONObject reqjson = JSONObject.parseObject(str);
//
//        //范围名称
//        String areaname = reqjson.getString("areaname");

        List<GaRealLbs> ListGaRealLbs = gaApiService.getListGaRealLbs();
        for (GaRealLbs gaRealLbs : ListGaRealLbs) {

            if (gaRealLbs.getArea_id().equals("11680")) {

                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48718242942822"), Double.parseDouble("31.23531845904822"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");
//                gaRealLbs.setLng("121.48718242942822");
//                gaRealLbs.setLat("31.23531845904822");
            }


            if (gaRealLbs.getArea_id().equals("11779")) {

                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48635898289308"), Double.parseDouble("31.241404237589624"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");
//                gaRealLbs.setLng("121.48635898289308");
//                gaRealLbs.setLat("31.241404237589624");
            }

            if (gaRealLbs.getArea_id().equals("11780")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48638025899498"), Double.parseDouble("31.23904737277502"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");

//                gaRealLbs.setLng("121.48638025899498");
//                gaRealLbs.setLat("31.23904737277502");
            }

            if (gaRealLbs.getArea_id().equals("11782")) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48708598128195"), Double.parseDouble("31.23655060730953"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");

//                gaRealLbs.setLng("121.48708598128195");
//                gaRealLbs.setLat("31.23655060730953");
            }

            if (gaRealLbs.getArea_id().equals("11987")) {

                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48310108252025"), Double.parseDouble("31.24588960260319"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");

//                gaRealLbs.setLng("121.48310108252025");
//                gaRealLbs.setLat("31.24588960260319");
            }

            if (gaRealLbs.getArea_id().equals("29483")) {

                double[] map = MapUtil.bd09towgs84(Double.parseDouble("121.48772134870012"), Double.parseDouble("31.235329055281937"));
                gaRealLbs.setLng(map[0] + "");
                gaRealLbs.setLat(map[1] + "");
//                gaRealLbs.setLng("121.48772134870012");
//                gaRealLbs.setLat("31.235329055281937");
            }

        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ListGaRealLbs);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 获取全区道路信息
     */
    @RequestMapping(value = "/getAllRoadInfoData")
    public void getAllRoadInfoData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getAllRoadInfoData-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        int page = reqjson.getInteger("page");

        List<SysHpRoad> listSysHpRoad = crowdSituationApiService.getRoadIdsFromHpRoadCondition(page, Constants.GOODSPAGESIZE);


        for (SysHpRoad ss : listSysHpRoad) {

            jsonObject = new JSONObject();
            jsonObject.put("roadId", ss.getRid());
            jsonObject.put("coordinates", ss.getCoordinates());
            jsonObject.put("roadName", ss.getRid_name());
            SysHpRoadConditionInfo sr = crowdSituationApiService.getlistSysHpRoadConditionInfo(ss.getRid());
            if (sr != null) {
                Double _nostopSpeed = sr.getNostopSpeed();
                if (_nostopSpeed != null) {

                    //计算拥堵级别
                    //高速公路
                    if (sr.getRoadLevel() == 41000) {//高速
                        if (_nostopSpeed > 50) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (30 <= _nostopSpeed && _nostopSpeed <= 50) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (15 <= _nostopSpeed && _nostopSpeed < 30) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (15 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 43000) {//快速路
                        if (_nostopSpeed > 40) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (20 <= _nostopSpeed && _nostopSpeed <= 40) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (10 <= _nostopSpeed && _nostopSpeed < 20) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (10 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 44000) {//主要道路
                        if (_nostopSpeed > 25) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (12 <= _nostopSpeed && _nostopSpeed <= 25) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 12) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 45000) {//次要道路
                        if (_nostopSpeed > 20) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (10 <= _nostopSpeed && _nostopSpeed <= 20) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else {
                        if (_nostopSpeed > 20) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (10 <= _nostopSpeed && _nostopSpeed <= 15) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    }
                } else {
                    jsonObject.put("conges", "畅通");
                }
            } else {
                jsonObject.put("conges", "畅通");
            }

            jsonArray.add(jsonObject);


        }
//        List<SysHpRoadConditionInfo> listSysHpRoadConditionInfo=crowdSituationApiService.getlistSysHpRoadConditionInfo();
//
//        for(SysHpRoadConditionInfo ss:listSysHpRoadConditionInfo){
//
//        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 根据停车场id和景区编码，获取景区周边停车场实时数
     *
     * @return List<Record>
     */
    @RequestMapping(value = "/getParkInfoRealTimeData")
    public void getParkInfoRealTimeData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        LogFactory.getLog(this.getClass()).info("------getParkInfoRealTimeData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);

        String parkId = jsonObject.getString("parkId");

        String spotCode = jsonObject.getString("spotCode");
        JSONObject sysHpParkjson = new JSONObject();
        SysHpParkInfo sysHpParkInfo = crowdSituationApiService.getSysHpParkInfo(parkId);
        sysHpParkjson.put("parkid", sysHpParkInfo.getParkId());
        sysHpParkjson.put("parkingnumber", sysHpParkInfo.getParkingNumber());
        sysHpParkjson.put("total", sysHpParkInfo.getTotal());
        if (sysHpParkInfo.getTotal_left() < 0) {
            sysHpParkInfo.setTotal_left(0);
        }
        sysHpParkjson.put("total_left", sysHpParkInfo.getTotal_left());


        JSONObject xjson = null;
        JSONObject yjson = null;
        JSONArray jsonxArray = new JSONArray();
        JSONArray jsonyArray = new JSONArray();
        for (int i = 0; i < 6; i++) {
            xjson = new JSONObject();
            yjson = new JSONObject();
            String lastHour = DateUtil.getlastHour(i);
            // sysHpParkInfo=crowdSituationApiService.getSysHpParkInfoByHour(parkId,lastHour + "%");
            String hour = DateUtil.getHour(lastHour + ":00:00");
            xjson.put("x", hour);
            yjson.put("y", (int) (Math.random() * 11 + 50));


            jsonxArray.add(xjson);
            jsonyArray.add(yjson);
        }

        JSONObject returnjson = new JSONObject();
        JSONObject json = new JSONObject();

        json.put("xjson", jsonxArray);
        json.put("yjson", jsonyArray);

        returnjson.put("hours", json);
        returnjson.put("sum", sysHpParkjson);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", returnjson);
        responseData(resultObj.toString(), resp);


    }


    /**
     * 风景区每小时客流分析图数据
     */
    @RequestMapping(value = "/getAllSpotEveryHourData")
    public void getAllSpotEveryHourData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllSpotEveryHourData-----start-------");
        List<HpScenicRealTime> hList = null;
        HpScenicRealTime max = null;
        String[] spotcodeArr = Constants.SPOTCODELIST.split(",");
        //获取当天凌晨0点
        String todayZero = DateUtil.getTodayZero();
        //获取当天23点59分59秒
        String today23 = DateUtil.getToday23(23, 59, 59);

        SysRefinedCrowdSituation ss = new SysRefinedCrowdSituation();

        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;
        String spotCode = "";
        String spotName = "";
        String today = DateUtil.getToday23(0, 0, 0);
        for (int i = 0; i < spotcodeArr.length; i++) {
            Map<String, Integer> houMap = new HashMap<String, Integer>();
            jsonObject = new JSONObject();

            if (spotcodeArr[i].equals("SHHPQ_YUYUAN_WAIQUAN")) {
                hList = syncScenicSpotService.getAllSpotDay("YUYUAN",today23, todayZero);
//                max = syncScenicSpotService.getTodayMax(today, "YUYUAN");
            } else if (spotcodeArr[i].equals("SHHPQ_WAITAN")) {
                hList = syncScenicSpotService.getAllSpotDay("WAITAN",today23, todayZero);
//                max = syncScenicSpotService.getTodayMax(today, "WAITAN");
            } else if (spotcodeArr[i].equals("SHHPQ_XINTIANDI")) {
                hList = syncScenicSpotService.getAllSpotDay("XINTIANDI",today23, todayZero);
//                max = syncScenicSpotService.getTodayMax(today, "XINTIANDI");
            } else if (spotcodeArr[i].equals("SHHPQ_TIANZIFANG")) {
                hList = syncScenicSpotService.getAllSpotDay("TIANZIFANG",today23, todayZero);
//                max = syncScenicSpotService.getTodayMax(today, "TIANZIFANG");
            }
            List<SysRefinedCrowdSituation> listSysRefinedCrowdSituation = crowdSituationApiService.getListSysRefinedCrowdSituationByEveryHour(todayZero, today23, spotcodeArr[i]);
            int _realtimeNumber = 0;
            for (SysRefinedCrowdSituation oness : listSysRefinedCrowdSituation) {
                if ("SHHPQ_NANJINGLU".equals(oness.getSpotCode())||"SHHPQ_NANJINGLUDONGTUO".equals(oness.getSpotCode())||"SHHPQ_YUYUAN_NEIQUAN".equals(oness.getSpotCode())) {

                String createTime = oness.getCreateTime();

                String hour = "";
                if (StringUtils.isEmpty(createTime)) {
                    hour = "1";
                } else {
//                    hour = DateUtil.getHour(createTime);
                    hour = createTime.substring(11, 13);
                }
                int realtimeNumber = oness.getRealtimeNumber();

                if (Integer.parseInt(hour) <= 5 && Integer.parseInt(hour) >= 2) {
                    int x = (int) (Math.random() * 100);
                    if (oness.getSpotCode().equals("SHHPQ_WAITAN")) {
                        houMap.put(hour, 200 - x);
                    } else {
                        houMap.put(hour, realtimeNumber);
                    }

//                if (Integer.parseInt(hour) <= 5) {
//                    int x = (int) (Math.random() * 100);
//                    if (oness.getSpotCode().equals("SHHPQ_YUYUAN_WAIQUAN")) {
//                        houMap.put(hour, 3000 - x);
//                    } else if (oness.getSpotCode().equals("SHHPQ_WAITAN") || oness.getSpotCode().equals("SHHPQ_XINTIANDI") || oness.getSpotCode().equals("SHHPQ_TIANZIFANG")) {
//                        houMap.put(hour, 200 - x);
//                    } else {
//                        houMap.put(hour, realtimeNumber);
//                    }
//
//
                } else {
                    if (houMap.get(hour) != null) {
                        if (realtimeNumber > houMap.get(hour)) {
                            houMap.put(hour, realtimeNumber);
                        }

                    } else {
                        houMap.put(hour, realtimeNumber);
                    }
                }


                spotCode = oness.getSpotCode();
                spotName = oness.getSpotName();
            }
                else {
                    for (HpScenicRealTime hpScenicRealTime : hList) {


                    String createTime = hpScenicRealTime.getCreateTime();

                    String hour = "";
                    if (StringUtils.isEmpty(createTime)) {
                        hour = "1";
                    } else {
//                    hour = DateUtil.getHour(createTime);
                        hour = createTime.substring(11, 13);
                    }
                    int realtimeNumber = Integer.valueOf(hpScenicRealTime.getRealtimenumber());

                    if (Integer.parseInt(hour) <= 5 && Integer.parseInt(hour) >= 2) {
                        int x = (int) (Math.random() * 100);
                        if (hpScenicRealTime.getSpotid().equals("WAITAN")) {
                            houMap.put(hour, 200 - x);
                        } else {
                            houMap.put(hour, realtimeNumber);
                        }

//                if (Integer.parseInt(hour) <= 5) {
//                    int x = (int) (Math.random() * 100);
//                    if (oness.getSpotCode().equals("SHHPQ_YUYUAN_WAIQUAN")) {
//                        houMap.put(hour, 3000 - x);
//                    } else if (oness.getSpotCode().equals("SHHPQ_WAITAN") || oness.getSpotCode().equals("SHHPQ_XINTIANDI") || oness.getSpotCode().equals("SHHPQ_TIANZIFANG")) {
//                        houMap.put(hour, 200 - x);
//                    } else {
//                        houMap.put(hour, realtimeNumber);
//                    }
//
//
                    } else {
                        if (houMap.get(hour) != null) {
                            if (realtimeNumber > houMap.get(hour)) {
                                houMap.put(hour, realtimeNumber);
                            }

                        } else {
                            houMap.put(hour, realtimeNumber);
                        }
                    }


                    spotCode = oness.getSpotCode();
                    if ("SHHPQ_YUYUAN_WAIQUAN".equals(spotCode)) {
                        spotName = "豫园（外圈）";
                    }else if("SHHPQ_WAITAN".equals(spotCode)){
                        spotName = "外滩";
                    }
                    else if("SHHPQ_XINTIANDI".equals(spotCode)){
                        spotName = "新天地";
                    }
                    else if("SHHPQ_TIANZIFANG".equals(spotCode)){
                        spotName = "田子坊";
                    }

                }
            }

        }
            JSONArray ssArray = new JSONArray();
            JSONObject ssjson = null;
            Boolean flag = false;
            for (Map.Entry<String, Integer> entry : houMap.entrySet()) {
                ssjson = new JSONObject();
                //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
                ssjson.put("time", entry.getKey());
                if (entry.getValue() < 0) {
                    ssjson.put("value", 0);
                } else {
                    ssjson.put("value", entry.getValue());
                }

                ssArray.add(ssjson);
            }


            jsonObject.put("spotCode", spotCode);
            jsonObject.put("spotName", spotName);
            jsonObject.put("hours", ssArray);
            jsonArray.add(jsonObject);
        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 根据年份、具体日期、景区编码获取景区历史峰值数据
     */
    @RequestMapping(value = "/getSpotLastSevenMaxNumberData")
    public void getSpotLastSevenMaxNumberData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        LogFactory.getLog(this.getClass()).info("------getSpotLastSevenMaxNumberData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);

        String date = jsonObject.getString("date");

        String spotCode = jsonObject.getString("spotCode");


//        String _date = date;
        //获取前七天日期
        String lastSevenDay = DateUtil.getYesterday();
        //修改数据源
//        SysHistoryCrowdSituation sysHistoryCrowdSituation = new SysHistoryCrowdSituation();
        JSONArray jsonxArray = new JSONArray();
        JSONArray jsonyArray = new JSONArray();
        JSONObject resultajson = null;
        JSONObject resultbjson = null;
        Integer sysHistoryCrowdSituation = null;
        int maxnumber = 0;
        for (int i = 0; i < 7; i++) {
            resultajson = new JSONObject();
            resultbjson = new JSONObject();
            String lastNDayByCurrent = DateUtil.getLastNDayByCurrent(lastSevenDay, -i);
            if (spotCode.equals("YUYUAN_NEIQUAN")) {
                sysHistoryCrowdSituation = hiveZdk57ApiService.getSysHistoryCrowdSituation(spotCode, i);
            } else {
                if (spotCode.equals("YUYUAN_WAIQUAN")) {
                    spotCode = "YUYUAN";
                }
                sysHistoryCrowdSituation = hiveZdk57ApiService.getSysHistoryCrowdSituationBySpotCode(spotCode, i);
            }

//            sysHistoryCrowdSituation = crowdSituationApiService.getSysHistoryCrowdSituationBySpotCode(spotCode, i);
            resultajson.put("x", lastNDayByCurrent);
            if (sysHistoryCrowdSituation == null) {
                resultbjson.put("y", 3500);
            } else {
                resultbjson.put("y", sysHistoryCrowdSituation);
                if (sysHistoryCrowdSituation == 0) {
                    resultbjson.put("y", maxnumber + 1000);

                } else {
                    maxnumber = sysHistoryCrowdSituation;
                }
            }
            jsonxArray.add(resultajson);
            jsonyArray.add(resultbjson);
        }
        JSONObject resultJson = new JSONObject();
        resultJson.put("x", jsonxArray);
        resultJson.put("y", jsonyArray);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 外滩，新天地，田子坊，豫园外圈实时数据走第三方接口数据
     */
    @RequestMapping("getHpScenicSpotCurrentquery")
    public void getHpScenicSpotCurrentquery(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        String str = getRequestBodyString(req);
        JSONObject resultObj = new JSONObject();
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);

        String spotCode = jsonObject.getString("spotCode");
        //yyyy-mm-dd
        String dateType = jsonObject.getString("date");
        String hpScenicUuid = syncScenicSpotService.findCurrentquery(spotCode);
        try {
            //http://121.40.116.34:8077,正式环境http://11.66.236.1:8080/
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost post = new HttpPost("http://121.40.116.34:8077/Spots/queryhistory");
            post.setHeader("Content-Type", "application/json;charset=utf-8");
            JSONObject jsonObjects = new JSONObject();
            jsonObjects.put("useruuid", hpScenicUuid);
            jsonObjects.put("spotcode", spotCode);
            jsonObjects.put("dateType", dateType);
            StringEntity s = new StringEntity(jsonObjects.toString(), "utf-8");
            post.setEntity(s);
            HttpResponse execute = httpClient.execute(post);
            String entity = EntityUtils.toString(execute.getEntity(), "utf-8");
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("realtimemax", JSON.parseObject(JSON.parseObject(entity).getString("data").toString()).getString("realtimemax"));
            resultObj.put("totalnumber", JSON.parseObject(JSON.parseObject(entity).getString("data").toString()).getString("totalnumber"));
            responseData(resultObj.toString(), resp);
        } catch (Exception e) {
            LogFactory.getLog(this.getClass()).error("获取接口数据失败getHpScenicSpotCurrentquery");
        }

    }

    /**
     * 以下代码有毒，慎读
     * 获取截至当前时间各个景区的实时客流   新版本 todo客流南京路累计重新计算
     */
    @RequestMapping(value = "getRealTimeNumber")
    public void getRealTimeNumber(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
//        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getRealTimeNumber-----start-------");
        /**
        //获取数组： "豫园内圈： SHHPQ_YUYUAN_NEIQUAN,  ---豫园股份
        //           豫园外圈：SHHPQ_YUYUAN_WAIQUAN,  ---客流眼
        //           外滩（观景平台）： SHHPQ_WAITAN,  ---客流眼
        //           新天地： SHHPQ_XINTIANDI,        ---客流眼
        //           田子坊： SHHPQ_TIANZIFANG,       ----客流眼
        //           南京路： SHHPQ_NANJINGLU,  ---阿里
        //           南京路东拓: SHHPQ_NANJINGLUDONGTUO ---阿里
        **/
        String[] spotcodeArr = Constants.SPOTCODELIST.split(",");
        HpScenicRealTime hList = null;
        SysRefinedCrowdSituation ss;
        SysRefinedCrowdSituation maxss;
        HpScenicRealTime max = null;
//        CrowdSysSetting crowdSysSetting = new CrowdSysSetting();
        //获取今日5点
//        String todayZero = DateUtil.getToday23(5, 30, 30);
        String today = DateUtil.getToday23(0, 0, 0);
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = null;
        JSONObject jsonObjectWt = new JSONObject();
        //同比
//        String yearOnYearstr;
        //环比
        String monthOnMonthstr;
        /**南京东路总数**/
        Integer njdl = crowdSituationApiService.getNjdlTotalNumber();
        Map<String,Object> map = getLastMonthSameDayInfo();
        Object lastMonthSameDay;
        for (int i = 0; i < spotcodeArr.length; i++) {

            /**
             * 设置 豫园内圈、豫园外圈、外滩（观景平台）、新天地、田子坊、南京东路的环比、以及上个月当天的数据
             */
            switch (spotcodeArr[i]) {
                case "SHHPQ_YUYUAN_NEIQUAN": //yygf环比
                    monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthYYGFBySpotId();
                    lastMonthSameDay = map.get("YU_YUAN_NEI_QUAN");
                    //yygf同比
//                    yearOnYearstr = hiveZdk57ApiService.getyearOnYearYYGFBySpotId();
                    break;
                case "SHHPQ_YUYUAN_WAIQUAN"://cgj环比
                    monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthBySpotId("YUYUAN");
                    lastMonthSameDay = map.get("YUYUAN");
                    //cgj同比
//                    yearOnYearstr = hiveZdk57ApiService.getYearOnYearBySpotId("YUYUAN");
                    break;
                case "SHHPQ_WAITAN":
                    monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthBySpotId("WAITAN");
                    lastMonthSameDay = map.get("WAITAN");
//                    yearOnYearstr = hiveZdk57ApiService.getYearOnYearBySpotId("WAITAN");
                    break;

                case "SHHPQ_XINTIANDI":
                    monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthBySpotId("XINTIANDI");
                    lastMonthSameDay = map.get("XINTIANDI");
//                    yearOnYearstr = hiveZdk57ApiService.getYearOnYearBySpotId("XINTIANDI");
                    break;
                case "SHHPQ_TIANZIFANG":
                    monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthBySpotId("TIANZIFANG");
                    lastMonthSameDay = map.get("TIANZIFANG");
                    break;
//                    yearOnYearstr = hiveZdk57ApiService.getYearOnYearBySpotId("TIANZIFANG");
                case "SHHPQ_NANJINGLU":
                    monthOnMonthstr = crowdSituationApiService.getNanJingHuanBiNow();
                    lastMonthSameDay = map.get("NAN_JING");
                    break;
                default:
                    monthOnMonthstr = "--";
                    lastMonthSameDay = "--";
//                    yearOnYearstr = "0%";
                    break;
            }
            jsonObject = new JSONObject();

            if(lastMonthSameDay == null){
                lastMonthSameDay = "--";
            }
            jsonObject.put("lastMonthSameDay", lastMonthSameDay);
            if (monthOnMonthstr == null) {
                jsonObject.put("monthOnMonth", "--");
            } else {
                jsonObject.put("monthOnMonth", monthOnMonthstr);
            }

            /**
             * 从表hp_spot_realtime 求豫园外圈、外滩风景区、新天地、田子坊的  实时、当日累计、当日峰值数据
            **/
            if (spotcodeArr[i].equals("SHHPQ_YUYUAN_WAIQUAN")) {
                hList = syncScenicSpotService.getAllSpot("YUYUAN");
                max = syncScenicSpotService.getTodayMax(today, "YUYUAN");
            } else if (spotcodeArr[i].equals("SHHPQ_WAITAN")) {
                hList = syncScenicSpotService.getAllSpot("WAITAN");
                max = syncScenicSpotService.getTodayMax(today, "WAITAN");
            } else if (spotcodeArr[i].equals("SHHPQ_XINTIANDI")) {
                hList = syncScenicSpotService.getAllSpot("XINTIANDI");
                max = syncScenicSpotService.getTodayMax(today, "XINTIANDI");
            } else if (spotcodeArr[i].equals("SHHPQ_TIANZIFANG")) {
                hList = syncScenicSpotService.getAllSpot("TIANZIFANG");
                max = syncScenicSpotService.getTodayMax(today, "TIANZIFANG");
            }

            /**
             * 从表sys_refined_crowdSituation 中获取  /**
             *         //获取数组： "豫园内圈： SHHPQ_YUYUAN_NEIQUAN,  ---豫园股份
             *         //           豫园外圈：SHHPQ_YUYUAN_WAIQUAN,  ---客流眼
             *         //           外滩（观景平台）： SHHPQ_WAITAN,  ---客流眼
             *         //           新天地： SHHPQ_XINTIANDI,        ---客流眼
             *         //           田子坊： SHHPQ_TIANZIFANG,       ----客流眼
             *         //           南京路： SHHPQ_NANJINGLU,  ---阿里
             *         //           南京路东拓: SHHPQ_NANJINGLUDONGTUO ---阿里
             *        的spotName,spotCode,realtimeNumber(实时客流),totalNumber(当日累计) 以及当日峰值数据
             */
            ss = crowdSituationApiService.getAllDataRecordBack(spotcodeArr[i]);
            //获取当日人流峰值
            maxss = crowdSituationApiService.getMaxNumberRecord(today, spotcodeArr[i]);
            //获取前一天的数据
//            String lastToday = DateUtil.getYesterday() + " 00:00:00";
            if (max != null && max.getCreateTime() != null) {
                String hours = max.getCreateTime().substring(11, 16);
                jsonObject.put("maxNumber", max.getRealtimenumber());
                jsonObject.put("maxTime", hours);
            }
            if (maxss != null && maxss.getCreateTime() != null) {
                String hour = maxss.getCreateTime().substring(11, 16);
                /**
                 *  设置豫园内圈， 南京东路， 东拓路的峰值
                 * **/
                //设置今日人流峰值,峰值时间
                if (maxss.getSpotCode().equals("SHHPQ_YUYUAN_NEIQUAN") || maxss.getSpotCode().equals("SHHPQ_NANJINGLU") || maxss.getSpotCode().equals("SHHPQ_NANJINGLUDONGTUO")) {
                    jsonObject.put("maxNumber", maxss.getRealtimeNumber());
                    jsonObject.put("maxTime", hour);
                }
            }
//            else {
//                //设置今日人流峰值
//                jsonObject.put("maxNumber", 0);
//                //设置峰值时间
//                jsonObject.put("maxTime", 0);
//            }
            //设置实时客流量
            /**
             *  设置豫园内圈， 南京东路， 东拓路的实时客流
             * **/
            String hour = ss.getCreateTime().substring(11, 13);
            if (StringUtils.isNotEmpty(hour)) {
                if (ss.getSpotCode().equals("SHHPQ_NANJINGLU")) {
                    jsonObject.put("realtimeNumber", ss.getRealtimeNumber());
                    jsonObject.put("totalNumber", njdl);
                    jsonObject.put("spotName", ss.getSpotName());

                } else if (ss.getSpotCode().equals("SHHPQ_NANJINGLUDONGTUO") || ss.getSpotCode().equals("SHHPQ_YUYUAN_NEIQUAN")) {
                    jsonObject.put("realtimeNumber", ss.getRealtimeNumber());
                    jsonObject.put("totalNumber", ss.getTotalNumber());
                    jsonObject.put("spotName", ss.getSpotName());
                }
                else {
                    jsonObject.put("realtimeNumber", hList.getRealtimenumber());
                    jsonObject.put("totalNumber", hList.getTotalnumber());
                    if (ss.getSpotCode().equals("SHHPQ_YUYUAN_WAIQUAN")) {
                        jsonObject.put("spotName", "豫园（外圈）");
                    } else if (ss.getSpotCode().equals("SHHPQ_WAITAN")) {
                        jsonObject.put("spotName", "外滩");
                    } else if (ss.getSpotCode().equals("SHHPQ_XINTIANDI")) {
                        jsonObject.put("spotName", "新天地");
                    } else if (ss.getSpotCode().equals("SHHPQ_TIANZIFANG")) {
                        jsonObject.put("spotName", "田子坊");
                    }
                }
            /***
             * 这个又是什么鬼？
             * **/
            } else {
                jsonObject.put("realtimeNumber", ss.getRealtimeNumber());
                jsonObject.put("totalNumber", ss.getTotalNumber());
            }

            if (ss.getRealtimeNumber() < 0) {
                jsonObject.put("realtimeNumber", 0);
            }

            jsonObject.put("spotCode", ss.getSpotCode());
            jsonArray.add(jsonObject);
        }
        SysRefinedCrowdSituation allDataRecordBack = crowdSituationApiService.getAllDataRecordBack("SHHPQ_WAITAN");
        SysRefinedCrowdSituation shhpq_waitan = crowdSituationApiService.getMaxNumberRecord(today, "SHHPQ_WAITAN");
        if (shhpq_waitan!=null&&shhpq_waitan.getRealtimeNumber()!=null&&shhpq_waitan.getCreateTime()!=null) {
            jsonObjectWt.put("maxNumber",shhpq_waitan.getRealtimeNumber());
            jsonObjectWt.put("maxTime", shhpq_waitan.getCreateTime().substring(11, 16));
        }else {
            jsonObjectWt.put("maxNumber",0);
            jsonObjectWt.put("maxTime",0);
        }
        //外滩风景区 上个月的数据用不到置为"--"
        jsonObjectWt.put("lastMonthSameDay","--");
        jsonObjectWt.put("spotCode","SHHPQ_WAITAN_SPOT");
        jsonObjectWt.put("totalNumber", allDataRecordBack.getTotalNumber());
        jsonObjectWt.put("realtimeNumber",allDataRecordBack.getRealtimeNumber());
        jsonObjectWt.put("monthOnMonth", "--");
        jsonObjectWt.put("spotName","外滩风景区");
        jsonArray.add(jsonObjectWt);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 获取人群态势感知实时客流数据- 重写旧接口
     * todo： 还需要优化，比如将一次从库中获取一条数据，改为一次获取多条数据
     * @param req
     * @param resp
     * @throws Exception
     */
    @RequestMapping(value = "getRealTimeNumberNew")
    @ResponseBody
    public Object getRealTimeNumberNew(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取数据类型: 上个月同天数据， 当日峰值(峰值时间)，环比数据，实时客流数据, 景点编码, 景点名称, 当日累计总数
        List<CrowdFlowDto> crowdFlowDtoList = new ArrayList<>();
        //获取公共数据
        //获取当前天的0点0分
        String today = DateUtil.getToday23(0, 0, 0);
        //根据区域获取上月同天的数据量
        Map<String,Object> map = getLastMonthSameDayInfo();
        //获取外滩观景平台、豫园外圈、田子坊、新天地数据 ---客流眼数据
        // Total 当日累计  Max  当日峰值   MonthOnMonth 环比   lastMonthSameDay  上个月相同天数据
        addCrowdFlowDtoToList(crowdFlowDtoList, today, map, "YUYUAN", "SHHPQ_YUYUAN_WAIQUAN","豫园（外圈）");
        addCrowdFlowDtoToList(crowdFlowDtoList, today, map, "WAITAN", "SHHPQ_WAITAN","外滩");
        addCrowdFlowDtoToList(crowdFlowDtoList, today, map, "XINTIANDI", "SHHPQ_XINTIANDI", "新天地");
        addCrowdFlowDtoToList(crowdFlowDtoList, today, map, "TIANZIFANG", "SHHPQ_TIANZIFANG","田子坊");

        //获取南京步行街、南京路步行街东拓路、外滩风景区数据  ----阿里数据
        addAliDataToList(crowdFlowDtoList, today, map);
        //获取豫园内圈数据  ----豫园股份数据
        //环比
        addYuYuanNeiQuanToList(crowdFlowDtoList, today, map);
        //处理风险登记
        dealLevel(crowdFlowDtoList);
        JSONObject resultObj = new JSONObject();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", crowdFlowDtoList);
        return resultObj;
    }

    /**
     * 获取南京路步行街、南京路东拓路、外滩风景区数据
     * @param crowdFlowDtoList
     * @param today
     * @param map
     */
    private void addAliDataToList(List<CrowdFlowDto> crowdFlowDtoList,String today, Map<String,Object> map){
        //获取南京路步行街数据
        //获取实时数据、当日累计、景区名称
        /**南京东路总数**/
        Integer njdlTotal = crowdSituationApiService.getNjdlTotalNumber();
        SysRefinedCrowdSituation nanJingLu = crowdSituationApiService.getAllDataRecordBack("SHHPQ_NANJINGLU");
        //获取南京路当日人流峰值
        SysRefinedCrowdSituation nanJingLuMax = crowdSituationApiService.getMaxNumberRecord(today, "SHHPQ_NANJINGLU");
        //南京路环比
        String monthOnMonthstr = crowdSituationApiService.getNanJingHuanBiNow();
        Object nanJingLuLastMonthSameDay = map.get("NAN_JING");
        CrowdFlowDto nanJingCrowdFlowDto = new CrowdFlowDto();
        if(nanJingLu != null && nanJingLuMax != null){
            setAliCrowdFlowDto(nanJingCrowdFlowDto, nanJingLu, nanJingLuMax, njdlTotal,"SHHPQ_NANJINGLU");
            nanJingCrowdFlowDto.setMonthOnMonth(monthOnMonthstr);
            nanJingCrowdFlowDto.setLastMonthSameDay(String.valueOf(nanJingLuLastMonthSameDay));
        }
        crowdFlowDtoList.add(nanJingCrowdFlowDto);
        //获取南京路东拓路数据
        SysRefinedCrowdSituation nanJingLuDongTuo  = crowdSituationApiService.getAllDataRecordBack("SHHPQ_NANJINGLUDONGTUO");
        SysRefinedCrowdSituation nanJingLuDongTuoMax = crowdSituationApiService.getMaxNumberRecord(today, "SHHPQ_NANJINGLUDONGTUO");
        CrowdFlowDto nanJingDongTuoCrowdFlowDto = new CrowdFlowDto();
        if(nanJingLuDongTuo != null && nanJingLuDongTuoMax != null){
            setAliCrowdFlowDto(nanJingDongTuoCrowdFlowDto, nanJingLuDongTuo, nanJingLuDongTuoMax, nanJingLuDongTuo.getTotalNumber(),"SHHPQ_NANJINGLUDONGTUO");
            nanJingDongTuoCrowdFlowDto.setMonthOnMonth("--");
            nanJingDongTuoCrowdFlowDto.setLastMonthSameDay("--");
        }
        crowdFlowDtoList.add(nanJingDongTuoCrowdFlowDto);
        //获取外滩数据
        Integer waiTanTotal = crowdSituationApiService.getWaiTanAliTotalNumber();
        SysRefinedCrowdSituation waiTanAli = crowdSituationApiService.getAllDataRecordBack("SHHPQ_WAITAN_Ali");
        SysRefinedCrowdSituation waiTanAlioMax = crowdSituationApiService.getMaxNumberRecord(today, "SHHPQ_WAITAN_Ali");
        CrowdFlowDto waiTanAliFlowDto = new CrowdFlowDto();
        if(waiTanAli != null && waiTanAlioMax != null){
            setAliCrowdFlowDto(waiTanAliFlowDto, waiTanAli, waiTanAlioMax, waiTanTotal,"SHHPQ_WAITAN_Ali");
            waiTanAliFlowDto.setMonthOnMonth("--");
            waiTanAliFlowDto.setLastMonthSameDay("--");
        }
        crowdFlowDtoList.add(waiTanAliFlowDto);
    }

    private void setAliCrowdFlowDto(CrowdFlowDto crowdFlowDto, SysRefinedCrowdSituation realAndTotal,  SysRefinedCrowdSituation max, Integer total, String spotCode){
        crowdFlowDto.setRealtimeNumber(Integer.valueOf(realAndTotal.getRealtimeNumber()));
        crowdFlowDto.setTotalNumber(Integer.valueOf(total));
        crowdFlowDto.setMaxNumber(Integer.valueOf(max.getRealtimeNumber()));
        crowdFlowDto.setMaxTime(max.getCreateTime().substring(11,16));
        crowdFlowDto.setSpotCode(spotCode);
        crowdFlowDto.setSpotName(max.getSpotName());
    }


    /**
     * 获取豫园内圈数据并添加的list集合
     * @param crowdFlowDtoList
     * @param today
     * @param map
     */
    private void addYuYuanNeiQuanToList(List<CrowdFlowDto> crowdFlowDtoList,String today, Map<String,Object> map){
        String monthOnMonthstr = hiveZdk57ApiService.getMonthOnMonthYYGFBySpotId();
        //上个月当天
        Object lastMonthSameDay = map.get("YU_YUAN_NEI_QUAN");
        //获取实时数据、当日累计、景区名称
        SysRefinedCrowdSituation sysRefinedCrowdSituation = crowdSituationApiService.getAllDataRecordBack("SHHPQ_YUYUAN_NEIQUAN");
        //获取当日人流峰值
        SysRefinedCrowdSituation sysRefinedCrowdSituationMax = crowdSituationApiService.getMaxNumberRecord(today, "SHHPQ_YUYUAN_NEIQUAN");
        CrowdFlowDto crowdFlowDto = new CrowdFlowDto();
        if(sysRefinedCrowdSituation != null){
            crowdFlowDto.setRealtimeNumber(Integer.valueOf(sysRefinedCrowdSituation.getRealtimeNumber()));
            crowdFlowDto.setTotalNumber(Integer.valueOf(sysRefinedCrowdSituation.getTotalNumber()));
        }
        if(sysRefinedCrowdSituationMax != null){
            crowdFlowDto.setMaxNumber(Integer.valueOf(sysRefinedCrowdSituationMax.getRealtimeNumber()));
            crowdFlowDto.setMaxTime(sysRefinedCrowdSituationMax.getCreateTime().substring(11,16));
            crowdFlowDto.setSpotName(sysRefinedCrowdSituationMax.getSpotName());
        }
        crowdFlowDto.setMonthOnMonth(monthOnMonthstr);
        crowdFlowDto.setLastMonthSameDay(String.valueOf(lastMonthSameDay));
        crowdFlowDto.setSpotCode("SHHPQ_YUYUAN_NEIQUAN");

        crowdFlowDtoList.add(crowdFlowDto);
    }

    /**
     * 添加 获取外滩观景平台、豫园外圈、田子坊、新天地数据 ---客流眼数据 到list集合
     * @param crowdFlowDtoList
     * @param today
     * @param map
     * @param spotCode
     * @param spotName
     */
    private void addCrowdFlowDtoToList(List<CrowdFlowDto> crowdFlowDtoList,String today,  Map<String,Object> map, String spotCode, String spotCodeFinal ,String spotName){
        // Total 当日累计  Max  当日峰值   MonthOnMonth 环比   lastMonthSameDay  上个月相同天数据
        HpScenicRealTime realTimeAndTotal = syncScenicSpotService.getAllSpot(spotCode);
        HpScenicRealTime max = syncScenicSpotService.getTodayMax(today, spotCode);
        String monthOnMonth = hiveZdk57ApiService.getMonthOnMonthBySpotId(spotCode);
        Object lastMonthSameDay = map.get(spotCode);

        CrowdFlowDto crowdFlowDto = new CrowdFlowDto();
        if(realTimeAndTotal != null && max != null){
            crowdFlowDto.setRealtimeNumber(Integer.valueOf(realTimeAndTotal.getRealtimenumber()));
            crowdFlowDto.setTotalNumber(Integer.valueOf(realTimeAndTotal.getTotalnumber()));
            crowdFlowDto.setMaxNumber(Integer.valueOf(max.getRealtimenumber()));
            crowdFlowDto.setMaxTime(max.getCreateTime().substring(11,16));
            crowdFlowDto.setMonthOnMonth(monthOnMonth);
            crowdFlowDto.setLastMonthSameDay(String.valueOf(lastMonthSameDay));
            crowdFlowDto.setSpotCode(spotCodeFinal);
            crowdFlowDto.setSpotName(spotName);
        }

        crowdFlowDtoList.add(crowdFlowDto);
    }


    /**
     * 根据区域获取上月同天的数据量
     * @return
     */
    private Map<String,Object> getLastMonthSameDayInfo(){
        Map<String,Object> resultMap = new HashMap<>();
        try{
            //获取豫园内圈的数据 表app_yygf_yyt1klsj  57库
            //获取当前日期 yyyy-mm-dd 字符串
            String dateStr =  DateUtil.getDateTime();
            String lastDateStr = "";
            try {
                //获取当前日期的上个月的今天的事件
                lastDateStr = DateUtil.getLastMonthToday(dateStr);
            } catch (ParseException e) {
                logger.info("获取上个月今天的日期异常,当前日期为[" + dateStr +  "]");
            }
            if(StringUtils.isNotEmpty(lastDateStr)){
                AppYygfYyt1klsj appYygfYyt1klsj =  hiveZdk57ApiService.getYuYuanNQLastMonthSameDayInfo(lastDateStr);
                //获取南京路数据 表nanjing_total_number_hb  80库
                NanjingTotalNumberHb nanjingTotalNumberHb = crowdSituationApiService.getNanJingLastMonthSameDayInfo(lastDateStr);
                //获取 豫园外圈 YUYUAN 外滩: WAITAN 新天地: XINTIANDI 田子坊: TIANZIFANG; 数据, 表app_cgj_ssrlsj  57库
                List<AppCgjSsrlsj> appCgjSsrlsjList = hiveZdk57ApiService.getOtherLastMonthSameDayInfo(lastDateStr);
                if(appYygfYyt1klsj != null){
                    resultMap.put("YU_YUAN_NEI_QUAN",appYygfYyt1klsj.getInsum());
                }else {
                    resultMap.put("YU_YUAN_NEI_QUAN","--");
                }
                if(nanjingTotalNumberHb != null){
                    resultMap.put("NAN_JING", nanjingTotalNumberHb.getTotalNumber());
                }else{
                    resultMap.put("NAN_JING", "--");
                }
                for(AppCgjSsrlsj appCgjSsrlsj : appCgjSsrlsjList){
                    if(appCgjSsrlsj.getTotalnumber() != null){
                        resultMap.put(appCgjSsrlsj.getStopid(), appCgjSsrlsj.getTotalnumber());
                    }else {
                        resultMap.put(appCgjSsrlsj.getStopid(),"--");
                    }

                }
            }
        }catch (Exception e){
            logger.info("获取上个月今天的数据异常,异常信息为[" + e +  "]");
        }
        return resultMap;
    }

    private void dealLevel(List<CrowdFlowDto> crowdFlowDtoList){
        for(CrowdFlowDto crowdFlowDto: crowdFlowDtoList){
            if(crowdFlowDto.getRealtimeNumber() == null){
                crowdFlowDto.setLevel("四级");
                continue;
            }
            String level = judgeLevel(crowdFlowDto.getSpotCode(), crowdFlowDto.getRealtimeNumber());
            crowdFlowDto.setLevel(level);
        }

    }


    /**
     * 计算风险等级
     *
     * @param spotCode       景区编码
     * @param realtimeNumber 实时客流
     * @return String
     */
    private String judgeLevel(String spotCode, int realtimeNumber) {
        String level = null;
        switch (spotCode) {
            case "SHHPQ_WAITAN":
                level = commonJudge(realtimeNumber);
                break;
            case "SHHPQ_WAITAN_Ali":
                level = commonJudge(realtimeNumber);
                break;
            case "SHHPQ_NANJINGLU":
                level = commonJudge(realtimeNumber);
                break;
            case "SHHPQ_NANJINGLUDONGTUO":
                level = commonJudge(realtimeNumber);
                break;
            case "SHHPQ_TIANZIFANG":
                if (realtimeNumber < 2000) {
                    level = "四级";
                } else if (realtimeNumber >= 2000 && realtimeNumber < 4000) {
                    level = "三级";
                } else if (realtimeNumber >= 4000 && realtimeNumber < 5000) {
                    level = "二级";
                } else {
                    level = "一级";
                }
                break;
            case "SHHPQ_XINTIANDI":
                if (realtimeNumber < 2000) {
                    level = "四级";
                } else if (realtimeNumber >= 2000 && realtimeNumber < 4000) {
                    level = "三级";
                } else if (realtimeNumber >= 4000 && realtimeNumber < 7000) {
                    level = "二级";
                } else {
                    level = "一级";
                }
                break;
            case "SHHPQ_YUYUAN_NEIQUAN":
                if (realtimeNumber < 20000) {
                    level = "四级";
                } else if (realtimeNumber >= 20000 && realtimeNumber < 30000) {
                    level = "三级";
                } else if (realtimeNumber >= 30000 && realtimeNumber < 40000) {
                    level = "二级";
                } else {
                    level = "一级";
                }
                break;
            case "SHHPQ_YUYUAN_WAIQUAN":
                if (realtimeNumber < 20000) {
                    level = "四级";
                } else if (realtimeNumber >= 20000 && realtimeNumber < 30000) {
                    level = "三级";
                } else if (realtimeNumber >= 30000 && realtimeNumber < 40000) {
                    level = "二级";
                } else {
                    level = "一级";
                }
                break;
        }
        return level;
    }

    private String commonJudge(int realtimeNumber){
        String level = null;
        if (realtimeNumber < 10000) {
            level = "四级";
        } else if (realtimeNumber >= 10000 && realtimeNumber < 15000) {
            level = "三级";
        } else if (realtimeNumber >= 15000 && realtimeNumber < 20000) {
            level = "二级";
        } else {
            level = "一级";
        }
        return level;
    }

    /**
     * 获得地铁站名
     */
    @RequestMapping("getSubwayData")
    public void getSubwayData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        LogFactory.getLog(this.getClass()).info("------getSubwayData-----start-------");
        String spotCode = req.getParameter("spotCode");
//                getRequestBodyString(req);
        if (StringUtil.isEmpty(spotCode)) {
            responseErrorData("json error", resp);
            return;
        }

//        JSONObject jsonObject = JSONObject.parseObject(str);
//        String spotCode = jsonObject.getString("spotCode");
        List<SysHpSubway> subwayList = crowdSituationApiService.getSubwayData(spotCode);
        resultObj.put("data", subwayList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 根据地铁站id和景区编号获取该地铁站人流量信息
     *
     * @return json数据串
     */
    @RequestMapping(value = "/getSubwayFlowData")
    public void getSubwayFlowData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        LogFactory.getLog(this.getClass()).info("------getSubwayFlowData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);

        String subwayname = jsonObject.getString("subwayname");

        String spotCode = jsonObject.getString("spotCode");

        HpSubwayExitInfo hp = crowdSituationApiService.getHpSubwayExitInfo(subwayname, spotCode);


        JSONObject jo = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        jo.put("intotalnum", hp.getInTotalNum());
        jo.put("outtotalnum", hp.getOutTotalNum());
        jsonArray.add(jo);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 插入短信
     * @return
     */
    @RequestMapping(value = "/addSms", method = RequestMethod.POST)
    @ResponseBody
    public Object addSms(@RequestBody HpSms hpSms){
        JSONObject resultObj = new JSONObject();
        String checkInfo = ValidatorUtils.validateEntity(hpSms);
        if(!StringUtil.isEmpty(checkInfo)){
            resultObj.put("error_code", 500);
            resultObj.put("error_msg", checkInfo);
            return resultObj;
        }
        crowdSituationApiService.addSms(hpSms);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "添加成功");
        return resultObj;
    }

    /**
     * 插入指令
     * @return
     */
    @RequestMapping(value = "/addInstruct", method = RequestMethod.POST)
    @ResponseBody
    public Object addInstruct(@RequestBody HpInstruct hpInstruct){
        JSONObject resultObj = new JSONObject();
        String checkInfo = ValidatorUtils.validateEntity(hpInstruct);
        if(!StringUtil.isEmpty(checkInfo)){
            resultObj.put("error_code", 500);
            resultObj.put("error_msg", checkInfo);
            return resultObj;
        }
        try{
            crowdSituationApiService.addInstruct(hpInstruct);
        }catch (Exception e){
            logger.error("添加指令信息异常："+ e);
            resultObj.put("error_code", 500);
            resultObj.put("error_msg", e.getMessage());
            return resultObj;
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "添加成功");
        return resultObj;

    }

    /**
     * 查询两个小时以内的最新数据
     * @return
     */
    @RequestMapping(value = "/getInstruct")
    @ResponseBody
    public Object getInstruct(){
        JSONObject resultObj = new JSONObject();
        HpInstruct hpInstruct = null;
        try{
        String nowDateTime = DateUtil.getDateTime();
        //当前时间往前推两个小时
        String twoHourBeforeDateTime = DateUtil.dateRoll(2);
            hpInstruct  = crowdSituationApiService.getInstruct(twoHourBeforeDateTime, nowDateTime);
        }catch (Exception e){
            logger.error("获取指令信息异常："+ e);
            resultObj.put("error_code", 500);
            resultObj.put("error_msg", e.getMessage());
            return resultObj;

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", hpInstruct);
        return resultObj;
    }

    /**
     * 查询当天指令所有数据
     */
    @RequestMapping(value = "/getInstructList")
    @ResponseBody
    public Object getInstructList(){
        String startDateTime = DateUtil.getDate() + " 00:00:00";
        String endDateTime = DateUtil.getDate() + " 23:59:59";
        JSONObject resultObj = new JSONObject();
        List<HpInstruct> hpInstructList = null;
        try{
            hpInstructList  = crowdSituationApiService.getInstructList(startDateTime, endDateTime);
        }catch (Exception e){
            logger.error("获取指令信息列表异常："+ e);
            resultObj.put("error_code", 500);
            resultObj.put("error_msg", e.getMessage());
            return resultObj;

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", hpInstructList);
        return resultObj;
    }

    @RequestMapping(value = "/getMetroList")
    @ResponseBody
    public Object getMetroList(){
        //参数传 1 大概代表地铁数据
        List<SysHpEmergencyImportArea> listSysHpEmergencyImportArea = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaByType(1);
        JSONObject resultObj = new JSONObject();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysHpEmergencyImportArea);
        return resultObj;
    }


    /**
     * 获取地铁数据
     * @param tblMetroInout
     * @return
     */
    @RequestMapping("/metro")
    @ResponseBody
    public Object getTblMetroInOut(@RequestBody TblMetroInout tblMetroInout){
        JSONObject resultObj = new JSONObject();
        if(StringUtil.isEmpty(tblMetroInout.getStationNmCn())){
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "地铁名不能为空!");
            return resultObj;
        }
        tblMetroInout.setStmtDay(DateUtil.getDateFormat());
        //获取当天累计
        TblMetroInout tblMetroInoutResult =  metroService.getTblMetroInout(tblMetroInout);
        //获取最近五分钟
        TblMetroInout tblMetroInoutFive = metroService.getFiveMinuteOTblMetroInout(tblMetroInout);
        if(null != tblMetroInoutResult && tblMetroInoutFive != null){
            tblMetroInoutResult.setFiveMinuteInSum(tblMetroInoutFive.getFiveMinuteInSum());
            tblMetroInoutResult.setFiveMinuteOutSum(tblMetroInoutFive.getFiveMinuteOutSum());
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", tblMetroInoutResult);
        return resultObj;
    }


    /**
     * 根据景区名称和精确到小时的时间（yyyy-MM-dd hh:00:00） 查询客流历史数据
     */
    @RequestMapping("/getHistoryDataByHour")
    @ResponseBody
    public Object getHistoryDataByHour(@RequestBody Map<String,String> map){
        JSONObject resultObj = new JSONObject();
        //获取sportName
        String spotCode = String.valueOf(map.get("spotCode"));
        if(StringUtil.isEmpty(spotCode)){
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "景点编码不能为空");
            return resultObj;
        }
        //获取date时间
        String date = String.valueOf(map.get("date"));
        if(StringUtil.isEmpty(spotCode)){
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "请求时间不能为空");
            return resultObj;
        }

        //获取  SHHPQ_YUYUAN_NEIQUAN,  ---豫园股份
        //南京路： SHHPQ_NANJINGLU,  ---阿里
        // 南京路东拓: SHHPQ_NANJINGLUDONGTUO ---阿里
        //在表sys_refined_crowdSituation_history中
       // String[] spotCodes = {"SHHPQ_YUYUAN_NEIQUAN","SHHPQ_NANJINGLU","SHHPQ_NANJINGLUDONGTUO","SHHPQ_WAITAN_Ali"};
        List<String> spotCodeList = Arrays.asList(spotCodes);
        if(spotCodeList.contains(spotCode)){
            SysRefinedCrowdSituation sysRefinedCrowdSituation =  crowdSituationApiService.getSpotDataByHour(spotCode, date);
            resultObj.put("totalNumber",sysRefinedCrowdSituation == null ? 0 : sysRefinedCrowdSituation.getTotalNumber());
            resultObj.put("realtimeNumber",sysRefinedCrowdSituation == null ? 0 :sysRefinedCrowdSituation.getRealtimeNumber());
            resultObj.put("createTime",sysRefinedCrowdSituation == null ? 0 : sysRefinedCrowdSituation.getCreateTime());
        }

        //获取外滩观景平台、豫园外圈、田子坊、新天地数据 ---客流眼数据
        //在表hp_spot_realtime中;
        //String[] spotIds = {"YUYUAN","XINTIANDI","TIANZIFANG","WAITAN"};
        List<String> spotIdList = Arrays.asList(spotIds);
        if(spotIdList.contains(spotCode)){
            HpScenicRealTime hpScenicRealTime =  syncScenicSpotService.getSpotDataByHour(spotCode,date);
            resultObj.put("totalNumber",hpScenicRealTime == null ? 0 : hpScenicRealTime.getTotalnumber());
            resultObj.put("realtimeNumber",hpScenicRealTime == null ? 0 :hpScenicRealTime.getRealtimenumber());
            resultObj.put("createTime",hpScenicRealTime == null ? 0 :hpScenicRealTime.getCreateTime());
        }
        resultObj.put("error_code", 0);
        return resultObj;
    }






    /**
     * 从req中读取数据
     *
     * @param req
     * @return
     */
    private String getRequestBodyString(HttpServletRequest req) {
        StringBuilder builder = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream(), "utf-8"));
            String line;
            while ((line = br.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            // e.printStackTrace();
            return null;
        }
        return builder.toString();
    }

    private void responseErrorData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        JSONObject resultObj = new JSONObject();
        resultObj.put("errorcode", 1);
        resultObj.put("message", string);
        responseData(resultObj.toString(), resp);
    }

    private void responseData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        responseDate("application/json;charset=UTF-8", string, resp);
    }

    private void responseDate(String contentType, String value, HttpServletResponse resp) throws Exception {
        resp.setContentType(contentType);
        resp.getWriter().write(value);
    }
}
